I want to use PowerShell to transfer files with FTP to an anonymous FTP server. I would not use any extra packages. How?
There must be no risk that the script hangs or crashes.
I want to use PowerShell to transfer files with FTP to an anonymous FTP server. I would not use any extra packages. How?
There must be no risk that the script hangs or crashes.
I am not sure you can 100% bullet proof the script from not hanging or crashing, as there are things outside your control (what if the server loses power mid-upload?) - but this should provide a solid foundation for getting you started:
I'm not gonna claim that this is more elegant than the highest-voted solution...but this is cool (well, at least in my mind LOL) in its own way:
As you can see, it uses that dinky built-in windows FTP client. Much shorter and straightforward, too. Yes, I've actually used this and it works!
Here's my super cool version BECAUSE IT HAS A PROGRESS BAR :-)
Which is a completely useless feature, I know, but it still looks cool \m/ \m/
PS. Helps a lot, when I'm wondering "did it stop working, or is it just my slow ASDL connection?"
I recently wrote for powershell several functions for communicating with FTP, see https://github.com/AstralisSomnium/PowerShell-No-Library-Just-Functions/blob/master/FTPModule.ps1. The second function below, you can send a whole local folder to FTP. In the module are even functions for removing / adding / reading folders and files recursively.
}
Goyuix's solution works great, but as presented it gives me this error: "The requested FTP command is not supported when using HTTP proxy."
Adding this line after
$ftp.UsePassive = $true
fixed the problem for me:The most trivial way to upload a binary file to an FTP server using PowerShell is using
WebClient.UploadFile
:If you need a greater control, that
WebClient
does not offer (like TLS/SSL encryption, etc), useFtpWebRequest
. Easy way is to just copy aFileStream
to FTP stream usingStream.CopyTo
:If you need to monitor an upload progress, you have to copy the contents by chunks yourself: