Results 1 to 4 of 4

Thread: [RESOLVED] Write filestream to an FTP path

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Location
    North Carolina
    Posts
    114

    Resolved [RESOLVED] Write filestream to an FTP path

    I need to write a filestream to an FTP path. Is this possible? Am I just doing it wrong?

    FTP path =

    Code:
    FTP://username:password@###.###.###.###/foldername/file.docx
    C# (Hope that does not matter) Code is as follows:
    Code:
    public Boolean CopyDoc(string OldDoc, string NewDoc)
            {
            try
                {
    
                byte[] byteArray = File.ReadAllBytes(OldDoc);
                using (MemoryStream mem = new MemoryStream())
                    {
                    mem.Write(byteArray, 0, (int)byteArray.Length);
                    
                    
                    using (FileStream fileStream = new FileStream(NewDoc,
                        System.IO.FileMode.CreateNew))
                        {
                        mem.WriteTo(fileStream);
                        }
                   
                    }
                return true;
                }
            catch (IOException e)
                {
                string myerrmsg = "The file '" + NewDoc + "' already exists.";
                if (e.Message == myerrmsg)
                    {
                    throw new IOException(myerrmsg);
    
                    }
                else
                    {
                    throw new IOException(e.Message);
                    }
                    return false;
                }
            catch (Exception e)
                {
                throw new Exception(e.Message);
                return false;
    
                }
            }

    Error i get:

    Code:
    The given path's format is not supported.
    You only have one life, make it worthwhile.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Write filestream to an FTP path

    Quote Originally Posted by kul2bme View Post
    C# (Hope that does not matter)
    Not to me it doesn't

    The error message would suggest that there is something not quite right with the path that you are trying to write to.

    Have you tried stepping through the code with the debugger? Have you checked that any path that you are creating is correct and valid, and what you expect it to be?

    You might be interested in taking a look at the following:

    http://www.vbforums.com/showthread.p...&highlight=ftp

    Hope that helps!!

    Gary

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Location
    North Carolina
    Posts
    114

    Re: Write filestream to an FTP path

    Thanks Gary! The link you provided was just what I needed. Works like a champ as is.
    You only have one life, make it worthwhile.

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Write filestream to an FTP path

    Hey,

    Good stuff, glad to hear it!!

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width