Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

need C# code in SSIS script task for downloading files from FTP server using proxy

$
0
0

Hi,

I am using the beow C# code for downloading the files from FTP. The file gets generated with error text which says.

error message : </H1><PRE>200 Type set to I.
200 PORT Command successful.
550 /ftp.txt: No such file or directory.</PRE></BODY></HTML>

        string file = "ftp.txt";
        string fileName = @"D:\Test\" + file;

        FtpWebRequest downloadRequest = (FtpWebRequest)FtpWebRequest.Create(ftp://ServerName+ "/" + file);
        downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile;
        //downloadRequest.Credentials = new NetworkCredential("UserName", "Password");

        WebProxy myProxy = new WebProxy();
        Uri newUri = new Uri(http://ProxyName:ProxyPortNo);
        // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
        myProxy.Address = newUri;
        // Create a NetworkCredential object and associate it with the 
        // Proxy property of request object.
        myProxy.Credentials = new NetworkCredential("USerName", "Password","Domain");
        downloadRequest.Proxy = myProxy;

  
        FtpWebResponse response = (FtpWebResponse)downloadRequest.GetResponse();
        Stream responseStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(responseStream);

        FileInfo downloadFile = new FileInfo(fileName);
        FileStream outputStream = new FileStream(fileName, FileMode.Append);

        Stream ftpStream = response.GetResponseStream();
        long cl = response.ContentLength;
        int bufferSize = 4096;
        int readCount;
        byte[] buffer = new byte[bufferSize];
        readCount = ftpStream.Read(buffer, 0, bufferSize);
        MessageBox.Show("Connected: Downloading File");
        while (readCount > 0)
        {
            outputStream.Write(buffer, 0, readCount);
            readCount = ftpStream.Read(buffer, 0, bufferSize);
            //Console.WriteLine(readCount.ToString());
        }

        ftpStream.Close();
        outputStream.Close();
        response.Close();
        MessageBox.Show("Downloading Complete");

Thanks,
Saikat


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>