FTP File Upload Issue - Please help

Aug 19, 2014 at 4:14 PM
Hi,

We had a file upload code working to a particular FTP location. I was trying to implement FTPClient instead of my old working code. I downloaded the latest version and wrote a sample code. Please find below the Code I used for FTP File Upload.
public static void OpenWrite()
        {

            var ftpClient = new FtpClient
            {
                Host = "sftp.****.com",
                Port = 21,
                DataConnectionEncryption = true,
                EncryptionMode = FtpEncryptionMode.Explicit,
                SocketKeepAlive = false,
                DataConnectionType = FtpDataConnectionType.AutoPassive,
                Credentials = new NetworkCredential("*****", "*****"),
                DataConnectionConnectTimeout = 3000000,
                DataConnectionReadTimeout = 3000000,
                ConnectTimeout = 3000000,
                ReadTimeout = 3000000,
                SocketPollInterval = 0
            };

           
            using (ftpClient)
            {
                var destPath = "/test.txt";
                var sourcePath = ApplicationBaseFolder + @"\test.txt";

                ftpClient.ValidateCertificate += (control, e) => { e.Accept = true; };

                const int BUFFER_SIZE = 64 * 1024; // 64KB buffer
                byte[] buffer = new byte[BUFFER_SIZE];
                using (Stream readStream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
                using (Stream writeStream = ftpClient.OpenWrite(destPath))
                {
                    while (readStream.Position < readStream.Length)
                    {
                        buffer.Initialize();
                        int bytesRead = readStream.Read(buffer, 0, BUFFER_SIZE);
                        writeStream.Write(buffer, 0, bytesRead);
                    }
                    writeStream.Flush();
                }
            }            
        }
On testing to a test FTP location, it worked great. But, When i Tried to our production FTP location, it failed with the following Error Log.
InterNetwork: 12.68.144.205
220-Security Notice
220-You are about to access a secured resource. AmerisourceBergen Specialty
220-Group reserves the right to monitor and/or limit access to this
220 resource at any time.
AUTH TLS
234 SSL enabled start the negotiation
Time to activate encryption: 0h 0m 0s, Total Seconds: 0.5468995.
USER sigmatau
331 Password required for sigmatau
PASS <omitted>
230-Welcome to AmerisourceBergen Specialty Group! Please watch this area
230-for important messages.
230 User sigmatau logged in.
PBSZ 0
200 PBSZ command successful
PROT P
200 PROT command successful
FEAT
211-Extensions supported:
  AUTH SSL
  AUTH TLS-P
  AUTH TLS
  AUTH TLS-C
  PROT
  PBSZ
  SIZE
  CCC
  REST STREAM
  MODE Z
  XSHA1
  INTEGRITY
  HASH
  CLNT
211 End of list
Text encoding: System.Text.ASCIIEncoding
InterNetwork: 12.68.144.205
220-Security Notice
220-You are about to access a secured resource. AmerisourceBergen Specialty
220-Group reserves the right to monitor and/or limit access to this
220 resource at any time.
AUTH TLS
234 SSL enabled start the negotiation
Time to activate encryption: 0h 0m 0s, Total Seconds: 0.1093799.
USER sigmatau
331 Password required for sigmatau
PASS <omitted>
230-Welcome to AmerisourceBergen Specialty Group! Please watch this area
230-for important messages.
230 User sigmatau logged in.
PBSZ 0
200 PBSZ command successful
PROT P
200 PROT command successful
Text encoding: System.Text.ASCIIEncoding
PWD
257 "/Home/sigmatau" is current directory
CWD /Home/sigmatau
250 CWD command successful
TYPE I
200 TYPE command successful
SIZE /test.txt
550 SIZE failed: File could not be found
EPSV
502 Command not implemented
PASV
227 Entering Passive Mode (10,212,18,22,11,225)
InterNetwork: 10.212.18.22
Disposing FtpClient object...
QUIT
221 Goodbye
Disposing FtpSocketStream...
System.Net.Sockets.SocketException (0x80004005): A connection attempt failed bec
ause the connected party did not properly respond after a period of time, or est
ablished connection failed because connected host has failed to respond 10.212.1
8.22:3041
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.FtpClient.FtpSocketStream.Connect(String host, Int32 port, FtpI
pVersion ipVersions) in c:\Sreehari\RnD\System.Net.FtpClient\source\FtpSocketStr
eam.cs:line 607
   at System.Net.FtpClient.FtpClient.OpenPassiveDataStream(FtpDataConnectionType
 type, String command, Int64 restart) in c:\Sreehari\RnD\System.Net.FtpClient\so
urce\FtpClient.cs:line 1130
   at System.Net.FtpClient.FtpClient.OpenPassiveDataStream(FtpDataConnectionType
 type, String command, Int64 restart) in c:\Sreehari\RnD\System.Net.FtpClient\so
urce\FtpClient.cs:line 1083
   at System.Net.FtpClient.FtpClient.OpenDataStream(String command, Int64 restar
t) in c:\Sreehari\RnD\System.Net.FtpClient\source\FtpClient.cs:line 1284
   at System.Net.FtpClient.FtpClient.OpenWrite(String path, FtpDataType type) in
 c:\Sreehari\RnD\System.Net.FtpClient\source\FtpClient.cs:line 1528
   at System.Net.FtpClient.FtpClient.OpenWrite(String path) in c:\Sreehari\RnD\S
ystem.Net.FtpClient\source\FtpClient.cs:line 1499
   at Examples.OpenWriteExample.OpenWrite() in c:\Sreehari\RnD\System.Net.FtpCli
ent\examples\OpenWrite.cs:line 77
   at Examples.MainClass.Main(String[] args) in c:\Sreehari\RnD\System.Net.FtpCl
ient\examples\Main.cs:line 28
Please help me to troubleshoot the issue.

Thanks,
Sreehari