Automate FTP from Windows PC

Advertisement

Spectraflame
Joined:
Posts:
5

Automate FTP from Windows PC

This is all new to me so forgive my ignorance. I have a local folder in the root of the C: drive of a Windows 10 PC. I would like to automate an FTP transfer to an external location. Where do I begin? Do I need to create a saved connection within WinSCP? Is there specific syntax necessary to automate this? Is it run from within WinSCP or controlled by a related batch file? Are there examples available to reference? This will be something that will run everyday at a specific time and transfer a single file using the same file name each day and overwrite the previous file on the destination.

Reply with quote

Advertisement

Spectraflame
Joined:
Posts:
5

I created what I thought was correct. Can anyone see any issues with this syntax? I tried to schedule it through Windows Scheduler but it did not run successfully.

# Connect to FTP Server using credentials
open sftp://USERNAME:PASSWORD@FTP_SITE.com/ -hostkey="ssh-rsa 2048 XX:XX:XX:XX/k="

# Locate Local PC Directory
lcd C:\METERING
cd /

# Upload Data
put *

# Disconnect from FTP
close

# Close WinSCP
exit

# Execute the script using a command like:
# "C:\Program Files (x86)\WinSCP\WinSCP.exe" /log="C:\TMP\GDS_LOG\WinSCP.log" /ini=nul /script="C:\TMP\UPTEST.txt"

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,658
Location:
Prague, Czechia

For a start, execute it manually.
Do you get any errors, when you try that?

Reply with quote

Spectraflame
Joined:
Posts:
5

I ran it manually from within Windows and the Task Scheduler log output stated it completed however no data was transferred. I created a test task just to see if WinSCP would open from the scheduler and it did. I then placed just the /script portion of the argument but it did not run. Is the " before the C:\ causing the issue? Is that necessary? There is also nothing being placed in the WINSCP.LOG file. Should the script be placed in the argument before the script to output to the log file?

It works fine if the log file part of the script is removed. Is the syntax wrong? I would like to have some type of log history of the transaction. Can that be accomplished in a single file?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,658
Location:
Prague, Czechia

I've meant manually from Windows command-line, not from Task Scheduler.

Reply with quote

Advertisement

Spectraflame
Joined:
Posts:
5

It did work after I corrected my spelling mistake. I was referencing a local directory that did not exist. Now I just need to find a way to send an email with the transfer status and this should be complete.

Reply with quote

Spectraflame
Joined:
Posts:
5

Currently the log file is being populated each time when the script is ran. Is there a way to truncate the log after X number of days so it does not continue to grow?

Reply with quote

Advertisement

You can post new topics in this forum