This project is read-only.

FTPS receiver says file is incomplete

Nov 23, 2012 at 9:49 PM

I am trying to upload a file to ABE Books... they are soon going to require FTPS.  I have the following code:

           // assign args to make it clear
            string userID = args[0];
            string password = args[1];
            string hostURL = args[2];
            string fileName = args[3];
            string directory = args[4];

            FileInfo fi = new FileInfo(args[3]);  //  get filename
            if (fi.Length == 0)  //  if file has a length of zero, return
                return 0;

            FTPSClient ftpsClient = new FTPSClient();
            ftpsClient.Connect(hostURL, new NetworkCredential(userID, password),
                ESSLSupportMode.CredentialsRequired | ESSLSupportMode.DataChannelRequested);

            ftpsClient.SetCurrentDirectory(directory);

            //  upload the file
            ftpsClient.PutFile(fileName);
            ftpsClient.Close();

            return 0;
        }

ABE's problem is that they say the file is "incomplete"...my problem is I am not familiar with FTPS, and can't find a C# example that shows me exactly how to use Alex FTPS.

Can someone please point me in the right direction?

Nov 23, 2012 at 10:19 PM

Hi, the best sample is the command line client that you can get here with the source code. 

Nov 26, 2012 at 8:46 PM
Edited Nov 27, 2012 at 12:19 AM

Alex:  I can't get it working... using this code:

 

        public int uploadFileUsingFTPS(string[] args) {

            // assign args to make it clear
            string userID = args[0];
            string password = args[1];
            string hostURL = args[2];
            string fileName = args[3];
            string directory = args[4];

            FileInfo fi = new FileInfo(args[3]);  //  get filename
            if (fi.Length == 0)  //  if file has a length of zero, return
                return -1;

            try {

                FTPSClient ftpsClient = new FTPSClient();
                ftpsClient.Connect(hostURL, new NetworkCredential(userID, password),
                    ESSLSupportMode.CredentialsRequired | ESSLSupportMode.DataChannelRequested);

                ftpsClient.SetTransferMode(ETransferMode.ASCII);
                ftpsClient.SetCurrentDirectory(directory);

                //  upload the file
                ftpsClient.PutFile(fileName);
                ftpsClient.Close();
            }
            catch (Exception ex) {
                MessageBox.Show("error: " + ex.Message);
                return -1;
            }

            return 0;

It is not being received by the host (they claim I am sending the "full local path" which makes no sense to me).  I thought it was because I didn't have a Close statement, but that didn't help either.

 

Is there a way that I can get the response from the server as to any errors as to why it wasn't successful?

Nov 27, 2012 at 2:16 PM

Any error is included in the exception thrown.

You can also log all the traffic, there's an option for that as well.

Nov 27, 2012 at 8:44 PM
Edited Nov 27, 2012 at 8:44 PM

Alex...  finally got it working... would you like to post my code for other C# developers to look at?  (It's well documented!) :D

 

Rolf 



Nov 27, 2012 at 9:53 PM

Sure! Can you post it here?

Nov 27, 2012 at 10:12 PM

Yes... do you want it posted as a reply to your posting above, or shall I put it up as a new project on Codeplex?