Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net;
- public class Program
- {
- public static void Main(string[] args)
- {
- //settings for the program to run...
- string uploadFile = string.Empty;
- string FTPServer = string.Empty;
- string FTPUser = string.Empty;
- string FTPPassword = string.Empty;
- if(args.Length != 4) //check if the parameters were set...
- {
- Console.WriteLine("Not all parameters were provided, please enter fields manually...");
- Console.WriteLine("Please enter the server IP: ");
- FTPServer = Console.ReadLine();
- Console.WriteLine("Please enter the FTP username: ");
- FTPUser = Console.ReadLine();
- Console.WriteLine("Please enter the FTP Password: ");
- FTPPassword = Console.ReadLine();
- Console.WriteLine("Please enter the file path to upload: ");
- uploadFile = Console.ReadLine();
- }
- else
- {
- //Get the command line arguements
- FTPServer = args[0];
- FTPUser = args[1];
- FTPPassword = args[2];
- uploadFile = args[3];
- }
- using(FileStream fs = File.OpenRead(uploadFile))
- {
- FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(FTPServer + "/" + uploadFile);
- ftp.Credentials = new NetworkCredential(FTPUser, FTPPassword);
- ftp.Timeout = -1; //no timeout for big files...
- ftp.KeepAlive = true;
- ftp.UseBinary = true;
- ftp.Method = WebRequestMethods.Ftp.UploadFile;
- fs.CopyTo(ftp.GetRequestStream()); //upload the file
- //Close the stream cause the upload is done...
- ftp.GetRequestStream().Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement