tags:

views:

8

answers:

0

Hi,

Doing some automated FTP work, like this:

    Dim ftpLocation As New Uri("myFTPSite")
    Dim credentials As New System.Net.NetworkCredential("username", "password")

    Dim ftpRequest As System.Net.FtpWebRequest = System.Net.FtpWebRequest.Create(ftpLocation.ToString() & fileName)
    ftpRequest.Credentials = credentials
    ftpRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

    Dim requestStream As FileStream = File.OpenRead(filePath)

    Dim buffer(requestStream.Length) As Byte
    requestStream.Read(buffer, 0, buffer.Length)
    requestStream.Close()
    requestStream = Nothing

    ftpRequest.GetRequestStream().Write(buffer, 0, buffer.Length)

    Dim response As System.Net.FtpWebResponse = DirectCast(ftpRequest.GetResponse(), System.Net.FtpWebResponse)
    If Not response.StatusCode = Net.FtpStatusCode.ClosingData Then
        Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("FTP transfer returned with a non-OK status code", "Linkshare", 1, 0, TraceEventType.Error)
        Throw New Exception()
    End If

    ftpRequest = Nothing

Which works fine in terms of actually uploading the desired file to the desired FTP server, but when I ask to examine the response, specifically the line

Dim response As System.Net.FtpWebResponse = DirectCast(ftpRequest.GetResponse(), System.Net.FtpWebResponse)

It just hangs and does nothing. It doesn't even seem to timeout. Any ideas why?

Cheers, Matt