4 Replies - 57368 Views - Last Post: 03 August 2009 - 03:09 PM Rate Topic: -----

#1 Backtracker  Icon User is offline

  • D.I.C Head

Reputation: -23
  • View blog
  • Posts: 163
  • Joined: 30-November 08

FTP Download & Delete...

Posted 22 December 2008 - 02:37 PM

Here's the basic code for the Download & Delete method what do i have to add ???

Download File...
	   Dim FTPRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(FTPServer & "something.dat"), System.Net.FtpWebRequest)
		FTPRequest.Credentials = New System.Net.NetworkCredential(FTPUsername, FTPPassword)
		FTPRequest.Method = System.Net.WebRequestMethods.Ftp.DownloadFile


Delete File...
	   Dim FTPRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(FTPServer & "something.dat"), System.Net.FtpWebRequest)
		FTPRequest.Credentials = New System.Net.NetworkCredential(FTPUsername, FTPPassword)
		FTPRequest.Method = System.Net.WebRequestMethods.Ftp.DeleteFile

This post has been edited by Backtracker: 22 December 2008 - 02:38 PM


Is This A Good Question/Topic? 0
  • +

Replies To: FTP Download & Delete...

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1632
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: FTP Download & Delete...

Posted 22 December 2008 - 03:19 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 yvrmurari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-July 09

Re: FTP Download & Delete...

Posted 27 July 2009 - 11:25 AM

I am trying to delete the file on FTP server using the method below. There is no error but the file is not being deleted. Please help

View PostBacktracker, on 22 Dec, 2008 - 01:37 PM, said:

Here's the basic code for the Download & Delete method what do i have to add ???

Download File...
	   Dim FTPRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(FTPServer & "something.dat"), System.Net.FtpWebRequest)
		FTPRequest.Credentials = New System.Net.NetworkCredential(FTPUsername, FTPPassword)
		FTPRequest.Method = System.Net.WebRequestMethods.Ftp.DownloadFile


Delete File...
	   Dim FTPRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(FTPServer & "something.dat"), System.Net.FtpWebRequest)
		FTPRequest.Credentials = New System.Net.NetworkCredential(FTPUsername, FTPPassword)
		FTPRequest.Method = System.Net.WebRequestMethods.Ftp.DeleteFile

Was This Post Helpful? 0
  • +
  • -

#4 LoveIsNull  Icon User is offline

  • Recovering D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 646
  • Joined: 10-March 09

Re: FTP Download & Delete...

Posted 27 July 2009 - 06:50 PM

Still a little tough to tell by glancing at a few lines of code, you sure the path is formatted correctly and you're not missing a \ some where or something?

This post has been edited by LoveIsNull: 27 July 2009 - 06:52 PM

Was This Post Helpful? 0
  • +
  • -

#8 madgeek81  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 1
  • Joined: 03-August 09

Re: FTP Download & Delete...

Posted 03 August 2009 - 03:09 PM

Here's what I use:

Download (RFN is Remote File Name/path, LFN is Local File Name/path as string):

Dim ftp As FtpWebRequest = CType(FtpWebRequest.Create(RFN), FtpWebRequest)
				console.writeline("Downloading: " & RFN)
				ftp.Credentials = New NetworkCredential("user", "pass")
				ftp.KeepAlive = False
				ftp.UseBinary = True
				ftp.Method = WebRequestMethods.Ftp.DownloadFile
				Using FtpResponse As FtpWebResponse = CType(ftp.GetResponse, FtpWebResponse)
					Using ResponseStream As IO.Stream = FtpResponse.GetResponseStream

						Using fs As New IO.FileStream(LFN, FileMode.Create)
							Dim buffer(2047) As Byte
							Dim read As Integer = 0
							Do
								read = ResponseStream.Read(buffer, 0, buffer.Length)
								fs.Write(buffer, 0, read)
								Console.Write(".")
							Loop Until read = 0
							ResponseStream.Close()
							fs.Flush()
							fs.Close()
							Log("")
						End Using
						ResponseStream.Close()

					End Using
				End Using


And to Delete:

console.writeline("Deleting From Server")
				Dim FTPDelReq As FtpWebRequest = WebRequest.Create(RFN)
				FTPDelReq.Credentials = New Net.NetworkCredential("user", "user")
				FTPDelReq.Method = WebRequestMethods.Ftp.DeleteFile
				Dim FTPDelResp As FtpWebResponse = FTPDelReq.GetResponse

Was This Post Helpful? 1

Page 1 of 1