«

»

Nov 12 2013

Print this Post

Automatically upload files to FTP server(s) using PowerShell

In the honor of taking a week off, I decided to share with you a script I’ve been asked to work on recently that automatically uploads a list of files to multiple FTP servers. Since I couldn’t find any native commands in PowerShell to work with FTP (Please leave comments if you know any), I decided to utilize the very handy “FTP.exe” that is built into windows. This tool can be used interactively from the command prompt, or accompanied with a script file with all the commands required.

The PowerShell script below basically reads data from a CSV files telling it the paths of each file to be uploaded, the FTP server (name or IP Address), username and password, and finally the path on the FTP server where the file should be sent to.

After the file paths are validated, the script will begin creating a “.s” file that is used at the end of the script to finally upload the data. Good guy FTP.exe also provides detailed log of the process which is all saved to a Log.log file for troubleshooting.

Here’s a flow chart of the logic of the script,

FTP Upload FlowChart

And below is the full script,



 

Finally for reference, this a sample CSV data to be used with the script, by default it looks for “.\UploadList.CSV” which should reside in the same folder as the PS1 file.

[plain]
Filepath,FTPServer,FTPUserName,FTPPassword,FTPPath
C:\Test1.txt,1.2.3.4,ftp,password,test\powershell
C:\Test2.txt,ftp.example.com,user,!password,\
[/plain]

Hope you find the information useful.

About the author

Walid AlMoselhy

Permanent link to this article: http://almoselhy.azurewebsites.net/2013/11/automatically-upload-files-to-ftp-servers-using-powershell/

2 comments

  1. Vikas Sukhija

    you can also use the below script that can upload files to ftp servers from a folder & than moved files to processed folder

    http://msexchange.me/2014/03/05/upload-files-to-ftp-server/

  2. mary

    I like the script, do you have one that downloads multiple files? I’m stuck on mine…
    Thanks,
    Mary

Leave a Reply

Your email address will not be published. Required fields are marked *