Free FTP Library [closed]
You may consider FluentFTP, previously known as System.Net.FtpClient. It is released under The MIT License and available on NuGet (FluentFTP).
You may consider FluentFTP, previously known as System.Net.FtpClient. It is released under The MIT License and available on NuGet (FluentFTP).
The existing answers are valid, but why re-invent the wheel and bother with lower level WebRequest types while WebClient already implements FTP uploading neatly: using (var client = new WebClient()) { client.Credentials = new NetworkCredential(ftpUsername, ftpPassword); client.UploadFile(“ftp://host/path.zip”, WebRequestMethods.Ftp.UploadFile, localFile); }
The easiest is to use BackgroundWorker and put your code into DoWork event handler. And report progress with BackgroundWorker.ReportProgress. The basic idea: private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { var ftpWebRequest = (FtpWebRequest)WebRequest.Create(“ftp://example.com”); ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile; using (var inputStream = File.OpenRead(fileName)) using (var outputStream = ftpWebRequest.GetRequestStream()) { var buffer = new byte[1024 * 1024]; int … Read more
I use a PHP Page to post a file to and have PHP handle the uploading…. This code is used to upload a photo, but it can be adapted to work with any file. PHP Code: <?php $uploaddir=”photos/”; $file = basename($_FILES[‘userfile’][‘name’]); $uploadfile = $uploaddir . $file; if (move_uploaded_file($_FILES[‘userfile’][‘tmp_name’], $uploadfile)) { echo “OK”; } else { … Read more
There’s no generic solution to this problem. Some FTP servers lock the file being uploaded, preventing you from accessing it, while the file is still being uploaded. For example IIS FTP server does that. Most other FTP servers do not. See my answer at Prevent file from being accessed as it’s being uploaded. There are … Read more
Not sure if you still need this, but this is the solution i came up with: Regex regex = new Regex ( @”^([d-])([rwxt-]{3}){3}\s+\d{1,}\s+.*?(\d{1,})\s+(\w+\s+\d{1,2}\s+(?:\d{4})?)(\d{1,2}:\d{2})?\s+(.+?)\s?$”, RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace ); Match Groups: object type: d : directory – : file Array[3] of permissions (rwx-) File Size Last Modified Date Last Modified Time File/Directory Name
For those looking for a full solution for finding the latest file in a folder: MLSD If your FTP server supports MLSD command, a solution is easy: entries = list(ftp.mlsd()) entries.sort(key = lambda entry: entry[1][‘modify’], reverse = True) latest_name = entries[0][0] print(latest_name) LIST If you need to rely on an obsolete LIST command, you have … Read more
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: # create the FtpWebRequest and configure it $ftp = [System.Net.FtpWebRequest]::Create(“ftp://localhost/me.png”) $ftp = [System.Net.FtpWebRequest]$ftp … Read more
For the first (DOS/Windows) listing this code will do: FtpWebRequest request = (FtpWebRequest)WebRequest.Create(“ftp://ftp.example.com/”); request.Credentials = new NetworkCredential(“user”, “password”); request.Method = WebRequestMethods.Ftp.ListDirectoryDetails; StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()); string pattern = @”^(\d+-\d+-\d+\s+\d+:\d+(?:AM|PM))\s+(<DIR>|\d+)\s+(.+)$”; Regex regex = new Regex(pattern); IFormatProvider culture = CultureInfo.GetCultureInfo(“en-us”); while (!reader.EndOfStream) { string line = reader.ReadLine(); Match match = regex.Match(line); string s = match.Groups[1].Value; DateTime … Read more
There are three options. You can use a native managed SFTP service recently added by Amazon (which is easier to set up). Or you can mount the bucket to a file system on a Linux server and access the files using the SFTP as any other files on the server (which gives you greater control). … Read more