FTP Upload (Encoding) problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry Spence1

    #1

    FTP Upload (Encoding) problem

    I have the following code (copied from the web somewhere) which I am using
    to upload some files:

    Dim Filename As String = Dir(OutBox)
    Do
    Dim request As FtpWebRequest =
    WebRequest.Crea te("ftp://<serverIP>/inbox/" & Filename)
    request.Method = WebRequestMetho ds.Ftp.UploadFi le
    request.UseBina ry = True

    request.Credent ials = New NetworkCredenti al("username",
    "password")

    Dim sourcestream As New StreamReader(Ou tBox & Filename)
    Dim Filecontents As Byte()
    Filecontents =
    Encoding.UTF8.G etBytes(sources tream.ReadToEnd ())
    sourcestream.Cl ose()
    request.Content Length = Filecontents.Le ngth

    Dim requestStream = request.GetRequ estStream()
    requestStream.W rite(Fileconten ts, 0, Filecontents.Le ngth)
    requestStream.C lose()
    Dim response = request.GetResp onse()
    response.Close( )
    File.Delete(Out Box & Filename)
    Filename = Dir()
    If Filename = "" Then Exit Do
    Loop

    I am copying jpg files so need a binary transfer. My problem is with the
    encoding line. I don't want any encoding - I just want to copy the file as
    it is. What should this line read?

    Or, of course, is there a better way to do it?

    -Jerry



  • tommaso.gastaldi@uniroma1.it

    #2
    Re: FTP Upload (Encoding) problem

    Hi jerry,

    if you do not need to take control of the stream
    why do not make life easier with (vb2005)

    My.Computer.Net work.UploadFile (sourcefile, TargetServerAnd FileName,
    UserId, Password, true, 1000)

    -tom

    Jerry Spence1 ha scritto:
    I have the following code (copied from the web somewhere) which I am using
    to upload some files:
    >
    Dim Filename As String = Dir(OutBox)
    Do
    Dim request As FtpWebRequest =
    WebRequest.Crea te("ftp://<serverIP>/inbox/" & Filename)
    request.Method = WebRequestMetho ds.Ftp.UploadFi le
    request.UseBina ry = True
    >
    request.Credent ials = New NetworkCredenti al("username",
    "password")
    >
    Dim sourcestream As New StreamReader(Ou tBox & Filename)
    Dim Filecontents As Byte()
    Filecontents =
    Encoding.UTF8.G etBytes(sources tream.ReadToEnd ())
    sourcestream.Cl ose()
    request.Content Length = Filecontents.Le ngth
    >
    Dim requestStream = request.GetRequ estStream()
    requestStream.W rite(Fileconten ts, 0, Filecontents.Le ngth)
    requestStream.C lose()
    Dim response = request.GetResp onse()
    response.Close( )
    File.Delete(Out Box & Filename)
    Filename = Dir()
    If Filename = "" Then Exit Do
    Loop
    >
    I am copying jpg files so need a binary transfer. My problem is with the
    encoding line. I don't want any encoding - I just want to copy the file as
    it is. What should this line read?
    >
    Or, of course, is there a better way to do it?
    >
    -Jerry

    Comment

    • Jerry Spence1

      #3
      Re: FTP Upload (Encoding) problem

      Thanks a lot Tom - I was sort of aware of that command in VB2005, but I
      hadn't appreciated its power.

      As a tip for others who come across this thread, the destination server must
      be ftp://<ipaddressor http://<ipaddressto get it to work.

      -Jerry




      <tommaso.gastal di@uniroma1.itw rote in message
      news:1155410813 .523301.280520@ b28g2000cwb.goo glegroups.com.. .
      Hi jerry,
      >
      if you do not need to take control of the stream
      why do not make life easier with (vb2005)
      >
      My.Computer.Net work.UploadFile (sourcefile, TargetServerAnd FileName,
      UserId, Password, true, 1000)
      >
      -tom
      >
      Jerry Spence1 ha scritto:
      >
      >I have the following code (copied from the web somewhere) which I am
      >using
      >to upload some files:
      >>
      > Dim Filename As String = Dir(OutBox)
      > Do
      > Dim request As FtpWebRequest =
      >WebRequest.Cre ate("ftp://<serverIP>/inbox/" & Filename)
      > request.Method = WebRequestMetho ds.Ftp.UploadFi le
      > request.UseBina ry = True
      >>
      > request.Credent ials = New NetworkCredenti al("username",
      >"password")
      >>
      > Dim sourcestream As New StreamReader(Ou tBox & Filename)
      > Dim Filecontents As Byte()
      > Filecontents =
      >Encoding.UTF8. GetBytes(source stream.ReadToEn d())
      > sourcestream.Cl ose()
      > request.Content Length = Filecontents.Le ngth
      >>
      > Dim requestStream = request.GetRequ estStream()
      > requestStream.W rite(Fileconten ts, 0, Filecontents.Le ngth)
      > requestStream.C lose()
      > Dim response = request.GetResp onse()
      > response.Close( )
      > File.Delete(Out Box & Filename)
      > Filename = Dir()
      > If Filename = "" Then Exit Do
      > Loop
      >>
      >I am copying jpg files so need a binary transfer. My problem is with the
      >encoding line. I don't want any encoding - I just want to copy the file
      >as
      >it is. What should this line read?
      >>
      >Or, of course, is there a better way to do it?
      >>
      >-Jerry
      >

      Comment

      • Jerry Spence1

        #4
        Re: FTP Upload (Encoding) problem

        Another tip is that I couldn't get ftp://123.456.789.012 to work. I don't
        know why, but I found that if I put a reference in my HOSTS table to a name
        (myserver) and then ftp://myserver worked just fine

        -Jerry

        _______________ _______________ _______________ __

        "Jerry Spence1" <jerry.spence@s omewhere.comwro te in message
        news:44deb910$0 $60313$ed2619ec @ptn-nntp-reader03.plus.n et...
        Thanks a lot Tom - I was sort of aware of that command in VB2005, but I
        hadn't appreciated its power.
        >
        As a tip for others who come across this thread, the destination server
        must be ftp://<ipaddressor http://<ipaddressto get it to work.
        >
        -Jerry
        >
        >
        >
        >
        <tommaso.gastal di@uniroma1.itw rote in message
        news:1155410813 .523301.280520@ b28g2000cwb.goo glegroups.com.. .
        >Hi jerry,
        >>
        >if you do not need to take control of the stream
        >why do not make life easier with (vb2005)
        >>
        >My.Computer.Ne twork.UploadFil e(sourcefile, TargetServerAnd FileName,
        >UserId, Password, true, 1000)
        >>
        >-tom
        >>
        >Jerry Spence1 ha scritto:
        >>
        >>I have the following code (copied from the web somewhere) which I am
        >>using
        >>to upload some files:
        >>>
        >> Dim Filename As String = Dir(OutBox)
        >> Do
        >> Dim request As FtpWebRequest =
        >>WebRequest.Cr eate("ftp://<serverIP>/inbox/" & Filename)
        >> request.Method = WebRequestMetho ds.Ftp.UploadFi le
        >> request.UseBina ry = True
        >>>
        >> request.Credent ials = New NetworkCredenti al("username",
        >>"password")
        >>>
        >> Dim sourcestream As New StreamReader(Ou tBox & Filename)
        >> Dim Filecontents As Byte()
        >> Filecontents =
        >>Encoding.UTF8 .GetBytes(sourc estream.ReadToE nd())
        >> sourcestream.Cl ose()
        >> request.Content Length = Filecontents.Le ngth
        >>>
        >> Dim requestStream = request.GetRequ estStream()
        >> requestStream.W rite(Fileconten ts, 0,
        >>Filecontents. Length)
        >> requestStream.C lose()
        >> Dim response = request.GetResp onse()
        >> response.Close( )
        >> File.Delete(Out Box & Filename)
        >> Filename = Dir()
        >> If Filename = "" Then Exit Do
        >> Loop
        >>>
        >>I am copying jpg files so need a binary transfer. My problem is with the
        >>encoding line. I don't want any encoding - I just want to copy the file
        >>as
        >>it is. What should this line read?
        >>>
        >>Or, of course, is there a better way to do it?
        >>>
        >>-Jerry
        >>
        >
        >

        Comment

        Working...