Пример #1
0
        //Method for downloading a file. Takes in a connection, a file name to get, and a directory to store the file in
        public String FileDownloadFromRemote(ServerConnectionInformation myConnection, string FileName, string DownloadDirectory)
        {
            String rememberServer = myConnection.ServerName;

            myConnection.ServerName = myConnection.ServerName + '/' + FileName;

            int bytesRead = 0;

            byte[] buffer = new byte[2048];
            try{
                FtpWebRequest myServerConnectionRequest = (FtpWebRequest)WebRequest.Create(myConnection.ServerName);
                myServerConnectionRequest.Credentials = new NetworkCredential(myConnection.UserName, myConnection.PassWord);
                myServerConnectionRequest.Proxy       = null;
                myServerConnectionRequest.UsePassive  = true;
                myServerConnectionRequest.UseBinary   = true;
                myServerConnectionRequest.KeepAlive   = true;

                myServerConnectionRequest.Method = WebRequestMethods.Ftp.DownloadFile;
                if (Directory.Exists(Path.GetDirectoryName(DownloadDirectory + "/" + FileName)) == false)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(DownloadDirectory + "/" + FileName));
                }

                Stream     StreamReader = myServerConnectionRequest.GetResponse().GetResponseStream();
                FileStream myFileStream = new FileStream(DownloadDirectory + "/" + FileName, FileMode.Create);

                while (true)
                {
                    bytesRead = StreamReader.Read(buffer, 0, buffer.Length);

                    if (bytesRead == 0)
                    {
                        break;
                    }

                    myFileStream.Write(buffer, 0, bytesRead);
                }
                myConnection.ServerName = rememberServer;
                myFileStream.Close();
                StreamReader.Close();
                return("success");
            }
            catch (WebException e) {
                myConnection.ServerName = rememberServer;
                if (e.Message.ToString().Equals("The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."))
                {
                    return("The server sent an error code of 550. The file may not exist.");
                }
                return(e.Message.ToString());
            } catch (Exception e)
            {
                myConnection.ServerName = rememberServer;
                return(e.Message.ToString());
            }
        } // end FileDownload()
Пример #2
0
 //A constructor for the class which takes in a ServerconnectionInformation to set up for its use.
 public CopyDirectory(ServerConnectionInformation toUse)
 {
     this.connection = toUse;
 }
Пример #3
0
 /*
  * Constructor which sets connection to the passed in SCI
  */
 public ChangePermissions(ServerConnectionInformation conn)
 {
     this.connection = conn;
 }
Пример #4
0
 /*
  * Constructor to set the class' connection to the one passed in
  */
 public DeleteFromRemote(ServerConnectionInformation toUse)
 {
     this.connection = toUse;
 }
Пример #5
0
 /*
  * Constructor which sets the class' ServerconnectionInformation to the one passed in
  */
 public ListFiles(ServerConnectionInformation toUse)
 {
     this.connection = toUse;
 }
Пример #6
0
 //constructor that pulls in the connection info and assigns it
 public FileDownloadMultiple(ServerConnectionInformation conn)
 {
     connection = conn;
 }
 //A constructor for the class which takes in a ServerconnectionInformation to set up for its use.
 public CreateRemoteDirectory(ServerConnectionInformation toUse)
 {
     this.connection = toUse;
 }
Пример #8
0
 /*
  * Constructor with a SCI to set for the class
  */
 public RenameFileRemote(ServerConnectionInformation toUse)
 {
     this.connection = toUse;
 }
Пример #9
0
 /*
  * Constructor with a SCI to set
  */
 public FileDownload(ServerConnectionInformation toUse)
 {
     this.connection = toUse;
 }
Пример #10
0
 //A constructor for the class which takes in a ServerconnectionInformation to set up for its use.
 public PutMultipleFiles(ServerConnectionInformation toUse)
 {
     this.connection = toUse;
 }
Пример #11
0
 /*
  * Sets the connection to the given ServerConnectionInformation
  */
 public void setConn(ServerConnectionInformation incoming)
 {
     this.connection = incoming;
 }