I can read/upload/download/delete files without issue with a
System.Net.FTP FtpClient ftpClient;
I won't have access to the production FTP site to enable MD5 or other hashing, so the only way I can think to validate my file uploads are comparing file sizes. Not 100% accurate, but for my purposes it will be close enough (just proving that a file was uploaded at a certain time).
The reason I'm coming to SO is that I can't find a lot of Q/A on trouble with System.Net.FTP ... My problem is that in my application, whether I
ftpClient.KeepSocketAlive = false;
//or
ftpClient.Discoect();
ftpClient.Coect();
//or
Thread.Sleep( /* A While */ );
//or
ftpClient.Dispose();
ftpClient = new FtpClient( userId, password, host );
//or even a separate thread
Thread t = new Thread( ()=>
{ /* Create a new instance of the FTP Client and upload my file*/ }
);
the file is uploaded but the attributes are empty. Keep in mind, the trouble is not waiting for the file to upload... my
bool Upload( string filename );
method waits until the transfer is complete and successful. I am rescaing the directory after the upload, and I am attempting a complete close and reopen of the coection.
The trouble is that I can't actually check the file attributes until one of the following thing happens: A) My application exits or B) I try to download or read the newly uploaded file from a separate application. The files show blank attributes and 0 bytes.
In fact, on my Test FTP site, I can use Explorer to see the folder directly on my network and the file size is indeed listed as 0 bytes... again, until I kill my upload application or until I read my file with notepad or whatever.
The only workaround I've come up with that works every time is a pretty bad code smell:
Thread.Sleep(500);
ProcessStartInfo psi = new ProcessStartInfo(
"FTPUploader.exe" , /* An FTP Upload Only Application */
"someFile.txt" ); /* With my file as an argument */
Process p = new Process();
/* Do that thing */
Thread.Sleep(500);
if( p.ExitCode == aCodeIMadeUp )
ValidateTheUpload();
I hate coding where people will look at the "solution" and ask "what the heck?"
I can tell that Filezilla can upload a file and the attributes are properly updated at the end of the upload cycle. Is Filezilla uploading on separate process altogether? Is there some basic functionality to FTP that I'm not understanding that will allow me to send a file, tell the server to reenumerate its own contents, so that file attributes are updated and subsequent reads show that actual file status? I'd like this code to work in a few different applications I'm plaing, and if my "solution" is crap, then it'll jest add to my headaches later. What's the answer here, Stack?
