Click here to Skip to main content
15,898,599 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Urgent. Please reply soon. I'm new to .net. Please reply....
Posted
Comments
ZurdoDev 5-May-15 12:47pm    
Where are you stuck? If you are in a hurry please search google for examples and you'll find what you need.
ZurdoDev 5-May-15 13:18pm    
How can we help?
ZurdoDev 5-May-15 13:27pm    
For what? Downloading a file from ftp? There are plenty of examples online. You could have been done by now.
ZurdoDev 5-May-15 14:08pm    
I doubt anyone would copy the content. I think you may be looking at the samples wrong. Either way, Solution 2 has some examples.

You question sounds as if you knew how to download one file. So, the answer is: download many one by one.

—SA
 
Share this answer
 
Comments
Kitty pandu 5-May-15 15:40pm    
Private Sub downloadFromFtp2()
Dim ftpreq As FtpWebRequest = DirectCast(WebRequest.Create("ftp://******/foldername/*.pgp"), FtpWebRequest)
Dim ftpreqname As FtpWebRequest = DirectCast(WebRequest.Create("ftp://******/foldername/"), FtpWebRequest)
ftpreq.Method = WebRequestMethods.Ftp.DownloadFile
ftpreqname.Method = WebRequestMethods.Ftp.ListDirectory
ftpreq.Credentials = New NetworkCredential("Username", "Password")
ftpreqname.Credentials = New NetworkCredential("Username", "Password")
Dim response As FtpWebResponse = CType(ftpreq.GetResponse, FtpWebResponse)
Dim nameresponse As FtpWebResponse = CType(ftpreqname.GetResponse, FtpWebResponse)
Dim responsestream As Stream = response.GetResponseStream
Dim responsestream_name As Stream = nameresponse.GetResponseStream
Dim reader As StreamReader = New StreamReader(responsestream)
Dim reader_name As StreamReader = New StreamReader(responsestream_name)
Dim dir As New List(Of String)
Dim line As String = reader_name.ReadLine
While Not String.IsNullOrEmpty(line)
dir.Add(line)
line = reader_name.ReadLine
end While
' reader_name.Close()
' nameresponse.Close()
Dim result As String = "0"
Dim count As Integer = 0
Dim endof As Integer = dir.Count - 1
For c As Integer = 0 To endof
If dir.Item(count).ToString.Contains(".pgp") Then
result = dir.Item(count).ToString
Else
End If
MsgBox(result)
Dim output As String = reader.ReadToEnd
' Dim output As Stream = File.Create("c:\foldername\.pgp")
Dim writer As StreamWriter = New StreamWriter("c:\foldername\" + result + ".pgp")
writer.Write(output)
MsgBox(response.StatusDescription)
count = count + 1
Next
' reader.Close()
' response.Close()
End Sub
Kitty pandu 5-May-15 15:43pm    
Above is the code. Reading the file name and giving the same name to the downloaded file in c:\ folder. While reading the second file ... Throws an error Cannot access a disposed object.object name: system.net.sockets.networkstream at the line dim output as string = reader. Readtoend
Sergey Alexandrovich Kryukov 5-May-15 15:59pm    
Well, don't use a disposed object, of course, create a new one. :-)
—SA
Kitty pandu 5-May-15 16:04pm    
Don't know where I'm going wrong. Can u look at the code and let me know
Sergey Alexandrovich Kryukov 5-May-15 17:06pm    
All right; in what line the exception is thrown?
And please move the code sample to the question using "Improve question".
—SA
For downloading one file you can use the below link and for multiple file just do it in loop one-by-one ;-)
But don`t forget probably you will need sleep time approximately around 1 second or you can find the best min sleep time by test.

https://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest(v=vs.100).aspx[^]
https://msdn.microsoft.com/en-us/library/ms229711(v=vs.110).aspx[^]

Question is not stupid, the answer is stupid.
R,
Aydin
 
Share this answer
 
v2
Comments
Kitty pandu 5-May-15 14:02pm    
The link above shows copying the content of file to the local folder. My requirement is I have folder 'A' on ftp ,which has files a and b. I want to download them to my local folder c:\.. .the downloaded file names should be same as the ones in ftp

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