Как составить скрипт удаления отосланных winscp файлов

от admin

Как составить скрипт удаления отосланных winscp файлов

I have to pick (remove) the files with file mask FileName_A_* and FileName_B_* from SFTP location and place them in an sharedrive.

I tried using WinSCP. I have created an HourlyFile.txt file with below code and placed it under C:\Program Files (x86)\WinSCP . Another batch file HourlyFile.bat to execute the script from HourlyFile.txt

I tried with below options to delete the file but got the error message «Unknown command». Also the above code is copying subfolder from /outbound/test/ , which it should not.

WinSCP — delete file after successful transfer (put/get)

Or how to control remotely an Android cellphone to take hundreds of thousands of pictures automatically, write a script to transfer the pictures continuously to a computer, delete them from the cellphone and then transfer the pictures to the cloud.

Control remotely an Android cellphone to take hundreds of thousands of pictures automatically, write a script to transfer the pictures continuously to a computer and then to the cloud.Control remotely an Android cellphone to take hundreds of thousands of pictures automatically, write a script to transfer the pictures continuously to a computer and then to the cloud.

WinSCP is my go-to tool whenever I’m in Windows and need to do SFTP transfers to/from a remote server.

From its website:

WinSCP is a popular SFTP client and FTP client for Microsoft Windows! Copy file between a local computer and remote servers using FTP, FTPS, SCP, SFTP, WebDAV or S3 file transfer protocols.

Most importantly, you can script WinSCP to do automatic operations.

The problem

My use case is that I have an Android cellphone (tried iPhone, impossible) taking pictures continuously for several days. After a couple of hours, the cellphone’s memory is full of pictures. The pictures need to be transferred to a computer and deleted from the cellphone, without stopping the camera from taking pictures, or touching the cellphone.

The Solution

So I decided to do a WinSCP script to transfer the pictures from the cellphone to the computer.

I installed on the cellphone an SSH Server app. Then I launched a Windows’ batch script that launched the WinSCP SFTP transfer script.

The Window’s batch script runs in an infinite loop. It transfers all the files from a folder in the cellphone to a folder on the computer. It deletes the file from the cellphone immediately after it has been transferred to the computer.

When all files have been transferred, it waits for 30 minutes and starts transferring files again.

To implement the waiting period in the script, I used the ping command, specifying a timeout and a number of 1 retries:

I copy below is copied the simple WinSCP script I use to transfer files from the cellphone’s SSH Server to a local computer and delete after the transfer.

The first line of the script is automatically generated by WinSCP, and the rest are common documented options and scripting commands.

Notice the -delete option, that deletes the file after a successful transfer.

I launch the WinSCP transfer script from a batch .bat file periodically, in an infinite loop, like so:

Notice that WinSCP.COM is in my Window’s PATH already.

Remote control (cellphone and/or computer)

By the way, since I sometimes need to operate my cellphone without touching it, I do it using the excellent and free-for-personal-use app Teamviewer.

I install this app both on the computer and the cellphone. That way I can control them remotely, without even being physically close to them.

Cloud Storage

Initially, I set up a cloud-sync service on the computer so that the pictures that were copied to the computer would be automatically uploaded to the cloud. I use a cloud-syncing service, such as MEGA.

Automatically syncing with MEGA was good for a while, but as the number of pictures increased to tens and hundreds of thousands, it became too slow.

Nowadays I use an awscli one-liner to sync the folder to an Amazon S3 bucket.

Camera App

To take the pictures I use another wonderful open-sourced app, OpenCamera (website and instructions).

OpenCamera can take pictures ad-infinitum, every N seconds, among many, many other wonderful settings.

Restarting all apps automatically

With such a long-lasting process — days, weeks —, I faced the issue that for some unknown reason Open Camera would stop taking pictures and/or TeamViewer would disconnect.

I solved this using another wonderful app called Automate. I use Automate to stop and restart all the apps on the cellphone. With Automate I can also start taking the pictures automatically by simulating a “tap” on OpenCamera ’s shutter.

This is enough information for now. I’d love to hear your comments and possible improvements to this process.

How do I create script that synchronizes files and deletes synchronized files from source afterward?

You have a source local (or remote) folder, where new files are being added by some external process. You want to make sure that these files gets regularly transferred to remote (or local) folder. And you want to remove the source local (or remote) files once they are safely transferred.

First of all, such an operation should not be called synchronization, as it does not end with source and destination folders being synchronized. Anyway, leaving a terminology aside…

Moving Files

Supposing you always want to upload (or download) all files from the source to the destination folder, you can simply move the files to the destination folder.

You can do this using -delete switch of the put (or get ) command. WinSCP deletes the source file, when it is successfully transferred to the destination folder only.

Synchronizing and Deleting Transferred Files

If it can happen that the same file is both in the source and the destination folder, and you do not want to upload (or download) such files, you can use synchronization and delete only transferred files afterward.

Читать:
Plaintextedit qt как взять текст

A simple way to implement this is using both -delete and -neweronly switches of the put (or get ) command

If you need more control (like if you want to delete the files only after all of them are transferred successfully), you can implement this easily using WinSCP .NET assembly. See example Deleting remote files after successful remote to local synchronization.

If you do not want to use .NET assembly: Perform the synchronization using synchronize command. Make sure the script generates XML log file. You can then parse the log file to enumerate files that got successfully transferred, and use the list, to generate script to delete the source copies.

WinSCP — delete file after successful transfer (put/get)

Or how to control remotely an Android cellphone to take hundreds of thousands of pictures automatically, write a script to transfer the pictures continuously to a computer, delete them from the cellphone and then transfer the pictures to the cloud.

Control remotely an Android cellphone to take hundreds of thousands of pictures automatically, write a script to transfer the pictures continuously to a computer and then to the cloud.Control remotely an Android cellphone to take hundreds of thousands of pictures automatically, write a script to transfer the pictures continuously to a computer and then to the cloud.

WinSCP is my go-to tool whenever I’m in Windows and need to do SFTP transfers to/from a remote server.

From its website:

WinSCP is a popular SFTP client and FTP client for Microsoft Windows! Copy file between a local computer and remote servers using FTP, FTPS, SCP, SFTP, WebDAV or S3 file transfer protocols.

Most importantly, you can script WinSCP to do automatic operations.

The problem

My use case is that I have an Android cellphone (tried iPhone, impossible) taking pictures continuously for several days. After a couple of hours, the cellphone’s memory is full of pictures. The pictures need to be transferred to a computer and deleted from the cellphone, without stopping the camera from taking pictures, or touching the cellphone.

The Solution

So I decided to do a WinSCP script to transfer the pictures from the cellphone to the computer.

I installed on the cellphone an SSH Server app. Then I launched a Windows’ batch script that launched the WinSCP SFTP transfer script.

The Window’s batch script runs in an infinite loop. It transfers all the files from a folder in the cellphone to a folder on the computer. It deletes the file from the cellphone immediately after it has been transferred to the computer.

When all files have been transferred, it waits for 30 minutes and starts transferring files again.

To implement the waiting period in the script, I used the ping command, specifying a timeout and a number of 1 retries:

I copy below is copied the simple WinSCP script I use to transfer files from the cellphone’s SSH Server to a local computer and delete after the transfer.

The first line of the script is automatically generated by WinSCP, and the rest are common documented options and scripting commands.

Notice the -delete option, that deletes the file after a successful transfer.

I launch the WinSCP transfer script from a batch .bat file periodically, in an infinite loop, like so:

Notice that WinSCP.COM is in my Window’s PATH already.

Remote control (cellphone and/or computer)

By the way, since I sometimes need to operate my cellphone without touching it, I do it using the excellent and free-for-personal-use app Teamviewer.

I install this app both on the computer and the cellphone. That way I can control them remotely, without even being physically close to them.

Cloud Storage

Initially, I set up a cloud-sync service on the computer so that the pictures that were copied to the computer would be automatically uploaded to the cloud. I use a cloud-syncing service, such as MEGA.

Automatically syncing with MEGA was good for a while, but as the number of pictures increased to tens and hundreds of thousands, it became too slow.

Nowadays I use an awscli one-liner to sync the folder to an Amazon S3 bucket.

Camera App

To take the pictures I use another wonderful open-sourced app, OpenCamera (website and instructions).

OpenCamera can take pictures ad-infinitum, every N seconds, among many, many other wonderful settings.

Restarting all apps automatically

With such a long-lasting process — days, weeks —, I faced the issue that for some unknown reason Open Camera would stop taking pictures and/or TeamViewer would disconnect.

I solved this using another wonderful app called Automate. I use Automate to stop and restart all the apps on the cellphone. With Automate I can also start taking the pictures automatically by simulating a “tap” on OpenCamera ’s shutter.

This is enough information for now. I’d love to hear your comments and possible improvements to this process.

Copy and delete files from SFTP folder

I have to pick (remove) the files with file mask FileName_A_* and FileName_B_* from SFTP location and place them in an sharedrive.

I tried using WinSCP. I have created an HourlyFile.txt file with below code and placed it under C:\Program Files (x86)\WinSCP . Another batch file HourlyFile.bat to execute the script from HourlyFile.txt

I tried with below options to delete the file but got the error message "Unknown command". Also the above code is copying subfolder from /outbound/test/ , which it should not.

Related Posts