Use Task Scheduler to call WinScp batch to upload and download files

Bulk upload

  1. Usually, when we run the dos command, we first click start-run, enter cmd to enter the dos interface, first enter the installation path of WinScp.exe to use the command to call it, otherwise it will prompt that the relevant command or parameter is not recognized. This entry process is very simple, type cd D:\InstallFile, type Enter, type D: to enter this path, 
    so we need to use the command
    cd D:\InstallFile
    D:
    here to ask the experts why they should enter D: again. , type Enter to enter the directory I want to enter?

  2. Enter the command to upload the file from the local to the ftp server. This command is also seen from the client's server, and the relevant information has not been found on the Internet. The final full command is as follows:

    copy code

    cd D:\InstallFile
    D:
    winscp421.exe
    /console /command

     "option batch continue"

     "option confirm off""open ftp://ftpuser1: ******@127.0.0.1:21"

     "option transfer binary""put D:\Documents\Coaching\English\*.txt /Newfolder/"

     "exit"

    copy code


    Here, for the convenience of understanding, they are explained one by one.
    winscp421.exe /console /command :: this is the command name
     "option batch continue" :: this default batch  
     "option confirm off" :: this is to avoid the prompt
    "open  ftp://ftpuser1****** @ 127.0.0.1 :21” :: This is the server to be accessed, here I access the ftp on this machine, using the username ftpuser1, password ******
    ”option transfer binary” :: This uses binary format to transfer
    ”put D:\Documents\Coaching\English\*.txt /Newfolder/” :: This uploads all txt files from the local folder and uploads them to the server Newfolder folder, note that these contents are placed in a parameter
     “exit” ::Exit after executing the command

  3. In order to take a screenshot, we remove the last parameter "exit", copy the above text to the txt file, modify the suffix to UploadFiles.bat, click Run, and you can see the running result as shown in Figure 1 below. As shown in the figure, you can see the name, size, transmission speed and other information of each file. As shown in

    Figure 1
    , we can see the file in the local path. As shown in Figure 2, all English learning materials are found on the Internet

    .

    

 

Batch download

Batch download is just the opposite of the above command, you only need to modify the command line, the code is as follows

cd D:\InstallFile

D:

winscp421.exe /console /command “option batch continue” “option confirm off” “open ftp://ftpuser1:****** @127.0.0.1 :21” “option transfer binary” “get /Newfolder/*. txt D:\Documents\DownLoad\" "exit"
From the code, we can see that we download all the txt files under the Newfolder folder in the server to D:\Documents\DownLoad, and also save the above text as DownloadFiles.bat, Click to run, the running interface is as shown in Figure 3

Setting environment variables
In order to find the executable program, the statement cd D:\InstallFile D: is added at the beginning of the above command. We can also add an environment variable to save the path, so that these two sentences can be omitted.

  1. Right-click Computer, click Properties, enter the Windows system interface, click Advance System Setting as shown in Figure 4

    Figure 4

  2. Click Environment Variables, enter the environment, double-click Path in User Variable, and add a new variable at the end to point to WinScp.exe as shown in Figure 5 and

    Figure 5

  3. After this setting, you can modify the UploadFiles.bat and DownloadFiles.bat files, and delete the two sentences cd D:\InstallFile D:. Doing java should be very familiar with this.

       

Adding Windows tasks
is now very convenient. Just click the bat file to upload and download, but it still feels very verbose, so we need to add these two bat files to the Task Scheduler, and set the schedule to let them run by themselves.

  1. Right-click Computer, click Manage, open Computer Management, as shown in Figure 6

    Figure 6

  2. Right-click Task Scheduler, click Create Basic Task, open the Create Basic Task Wizard interface, and enter the name of the task, as shown in Figure 7 and

    Figure 7

  3. Click Next to enter the Trigger interface and keep the default settings to run every day, as shown in Figure 8

    Figure 8

  4. Click Next, the default Start a programe, as shown in Figure 9

    Figure 9

  5. Click Next to enter the Start a Program interface, and select the bat file we just generated as shown in Figure 10

    Figure 10

  6. Click Next, click Finish, and then you can see our new task in the Task Scheduler Library. Figure 11

    Figure 11

  7. Double-click to set the running properties, click Triggers, and set it to run every 5 minutes, as shown in Figure 12 and

    Figure 12.

    At this point, we are done. Every 5 minutes, we can see a black dos dialog box pop up, and then disappear quickly, which proves that our setting is successful. Now, the program is running according to the settings, and you can view the uploaded files by viewing the corresponding directory at the same time. You can also add DownloadFiles.bat to the Windows task. This thing can be used next time when there is such a simple but large amount of copy-paste task, it will save trouble.


        </div>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325789034&siteId=291194637