-
Apr 2nd, 2013, 07:40 PM
#1
Thread Starter
New Member
FTPWebrequest won't make directory
Hey,
I have this code:
Code:
Dim Dir = ftphost & d.ToString("/yyyy")
Dim ftpReq As FtpWebRequest = WebRequest.Create(Dir)
ftpReq.Credentials = New NetworkCredential(ftpun, ftppass)
ftpReq.Method = WebRequestMethods.Ftp.MakeDirectory
Dir = (ftphost & d.ToString("/yyyy/") & d.ToString("MM"))
Dim a As FtpWebRequest = WebRequest.Create(Dir)
a.Credentials = New NetworkCredential(ftpun, ftppass)
a.Method = WebRequestMethods.Ftp.MakeDirectory
Dir = ftphost & d.ToString("/yyyy/") & d.ToString("MM/") & d.ToString("dd")
Dim c As FtpWebRequest = WebRequest.Create(Dir)
c.Credentials = New NetworkCredential(ftpun, ftppass)
c.Method = WebRequestMethods.Ftp.MakeDirectory
MsgBox("DONE")
Assuming that ftpun and ftppass is correct why won't the directory be made. It does not output all it does is shows as done but its not made a folder. Why wont it work? I have tried using functions and different methods but it still wont work.
Thanks,
Zacy5000
-
Apr 3rd, 2013, 02:13 AM
#2
Re: FTPWebrequest won't make directory
Just a quick thought since we don't have a stack trace here. Have you logged into your FTP server with an FTP Client (filezilla, command prompt, etc) and tried to make a directory with those credentials? Does it work or not work?
-
Apr 3rd, 2013, 04:40 AM
#3
Thread Starter
New Member
Re: FTPWebrequest won't make directory
Yes I have and it works perfect on filezilla.
-
Apr 3rd, 2013, 09:15 AM
#4
Re: FTPWebrequest won't make directory
This is a private sub that creates an FTP directory. You could easily turn it into a function as well if you would like a little more control of the result. If you are using a GUI though, it should be fine. Try it out and let us know how you fare.
Code:
Imports System.Net
Imports System.IO
Private Sub MakeDir(ByVal dirName As String, ByVal ServerIP as String, ByVal UserId as String, ByVal Password as String)
Dim reqFTP As FtpWebRequest = Nothing
Dim ftpStream As Stream = Nothing
Try
reqFTP = DirectCast(FtpWebRequest.Create(New Uri("ftp://" + ServerIP + "/" + dirName)), FtpWebRequest)
reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory
reqFTP.UseBinary = True
reqFTP.Credentials = New NetworkCredential(UserId, Password)
Dim response As FtpWebResponse = DirectCast(reqFTP.GetResponse(), FtpWebResponse)
ftpStream = response.GetResponseStream()
ftpStream.Close()
response.Close()
Catch ex As Exception
If ftpStream IsNot Nothing Then
ftpStream.Close()
ftpStream.Dispose()
End If
Throw New Exception(ex.Message.ToString())
End Try
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|