Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In DB i have give ftp address as 192......., and while i am updating the same in the code i am getting error as the given path format is not supoorted,please suggeste.

What I have tried:

public int upload(String SourceFilePath, FileInfo file1)
		{		   	
			try {
				using (WebClient client = new WebClient()) {	
					try {
						client.Credentials = mycreds;
						client.UploadFile(@"ftp:\\"+FTPIP +Path.GetFileName(SourceFilePath), SelectedPath + file1.Extension);
					} catch (Exception e2) {
						MessageBox.Show(e2.Message);
					}
				}
Posted
Updated 22-May-18 2:26am
Comments
[no name] 22-May-18 9:02am    
Did you verify in the debugger the strings passed to UploadFile are correct? Is there a path separator (slash) between FTPIP and the path?
Richard Deeming 22-May-18 10:55am    
1) FTP paths use forward-slashes as the path separator. You're using backslashes.
Replace @"ftp:\\" with "ftp://"

2) You don't seem to have a separator between the FTP server address and the file name.
Add a separator in ... + FTPIP + Path.GetFileName(... so that it becomes ... + FTPIP + "/" + Path.GetFileName(...


If it still doesn't work, debug your code and ensure that you're passing in the correct paths.
Member 13818142 22-May-18 23:36pm    
@Richard Thanks it worked...

WebClient client = new WebClient();
client.Credentials = new NetworkCredential("username", "password");
client.DownloadFile(
"ftp://ftp.example.com/remote/path/file.zip", @"C:\local\path\file.zip");
 
Share this answer
 
Comments
Member 13818142 22-May-18 8:29am    
Its not to download a file need to upload encrypted file to ftp
void Upload(){
    Web client = new WebClient();
    client.Credentials = new NetworkCredential(username, password);
    client.BaseAddress = "ftp://ftpsample.net/";

    client.UploadFile("sample.txt", "sample.txt"); //since the baseaddress
}
 
Share this answer
 
Comments
Member 13818142 22-May-18 8:33am    
I have already assigned ftp address and details as public and declared in btnupload,in db i have just declared ftp address as 192... with out updating it to ftp:// so how can i combine this ftp:// to the above code.

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