Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void Upload(string filename)
        {
            string ftpHost = ftpServerIP;
            //here correct hostname or IP of the ftp server to be given  
            FileInfo fileInf = new FileInfo(filename);
            string ftpFullPath = "ftp://" + ftpHost + fileInf.Name;
            MessageBox.Show(ftpFullPath);
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpFullPath);
            ftp.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
            //userid and password for the ftp server to given  
            ftp.KeepAlive = true;
            ftp.UseBinary = true;
            ftp.Method = WebRequestMethods.Ftp.UploadFile;
            FileStream fs = File.OpenRead(filename);
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            fs.Close();
            Stream ftpStream = ftp.GetRequestStream();
            ftpStream.Write(buffer, 0, buffer.Length);
}


[edit]Added pre tag[/ediit]

When I assign proxy it gives the exception
ftp.Proxy = new System.Net.WebProxy("http://10.16.5.39:3128/", true);
"The requested FTP command is not supported when using HTTP proxy."
When I set ftp.Proxy = null; it gives the exception
"Unable to connect to the remote server"
Help me to solve the issue.
Posted
Updated 19-Feb-12 21:47pm
v2

1 solution

Dear Friend,

Thee is a property for a FtpWebRequest. Just initialize it with an empty instance...

myFtpRequestObj.Proxy = new WebProxy();


The problem can be solved using

request.Proxy = nothing
 
Share this answer
 
v3
Comments
Simon O'Riordan from UK 23-Apr-13 5:43am    
Nice one Vareen. Just the first line(new WebProxy()), inserted into the standard code after the webrequest has been created and recast, ws sufficient to give me access to a test ftp site through a troublesome proxy. The sysadmin must love us!
Varun Sareen 24-Apr-13 8:35am    
thanks dear :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900