Copy files from local server folder to FTP server

 I need to copy files from local server folder (ie. C:\Temp\) to a FTP server folder (ie. ftp://ftp.abc.com/destFolder/). How can I do that using FileInfo.CopyTo(ftpaddress) and FtpWebRequest handle?   

 

0
hbcontract2002
7/11/2008 3:09:00 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

5 Replies
949 Views

Similar Articles

[PageSpeed] 13
Get it on Google Play
Get it on Apple App Store

Hi,

The below code is about FTP uploading.

    using System.IO;
    using System.Net;

 
private void FTPUpload(string filename, string ftpServerIP1 )
{
FileInfo fileInf = new FileInfo(filename); 
string uri = "ftp://" + ftpServerIP1 + "/" + fileInf.Name;
FtpWebRequest reqFTP; 
// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebRequest.Create 
(new Uri("ftp://" + ftpServerIP1 + "/" + fileInf.Name));
// Provide the WebPermission Credintials 
reqFTP.Credentials = new NetworkCredential(ftpUserID1, ftpPassword1); 
// By default KeepAlive is true, where the control connection
// is not closed after a command is executed. 
reqFTP.KeepAlive = false; 
// Specify the command to be executed. 
reqFTP.Method = WebRequestMethods.Ftp.UploadFile; 
// Specify the data transfer type. 
reqFTP.UseBinary = true; 
// Notify the server about the size of the uploaded file
reqFTP.ContentLength = fileInf.Length;
int buffLength = 500447300; 
byte[] buff = new byte[buffLength];

int contentLen; 
// Opens a file stream (System.IO.FileStream) to read the file
// to be uploaded 
FileStream fs = fileInf.OpenRead(); 
try
{
  // Stream to which the file to be upload is written 
  Stream strm = reqFTP.GetRequestStream(); 
  // Read from the file stream 2kb at a time
  contentLen = fs.Read(buff, 0, buffLength);
  // Till Stream content endswhile (contentLen != 0) 
  {

    // Write Content from the file stream to the FTP Upload
    // Stream

    strm.Write(buff, 0, contentLen);
    contentLen = fs.Read(buff, 0, buffLength);
  }

  strm.Close();
  fs.Close();

}
catch(Exception ex) 
{

   throw new Exception(ex.Message); 
}

}
 

You can check all files in the folder and call this function to achieve uploading.

Hope it helps.

 



Vince Xu
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Vince
7/15/2008 2:25:59 AM

is there another way other than read and write to the FTP upload stream? Is there a way just to Copy the whole file over without read and write (like using File.Copy()) ?

0
hbcontract2002
7/16/2008 12:11:10 AM

 

You can use either WebRequest or FtpWebRequest.

Then call uploadfile method.

0
itsumapathyk
7/16/2008 12:35:14 AM

Hi,

As far as I know, it's not available to copy a file to Ftp server directly via Copy() or CopyTo(). It needs transfer the file content to Ftp server via stream.



Vince Xu
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Vince
7/16/2008 3:01:38 AM
0
Punithkumar
7/16/2008 5:53:10 AM
Reply:

Similar Artilces:

copy file from web server to ftp server -- not working!
I've tried numerous iterations of the concept below, but I just can't get this to work.  We have a support page where users can upload files to the web server.  This works fine.  Now there is a request to post them to the company's ftp server.  This is the part I am having trouble with.  The code below gives the error: File Save error: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at ASP.form2_aspx.UploadToFTP(String filename, String ftpServerIP1) in e:\wwwroot\mysite\Form2.aspx:line 1203 at ASP.form2_asp...

server to server file copy
Hi, I''m in a different city than my servers and I want to copy a large folder from one volume to another on the same server. If I do this from my workstation, it copies the files to my workstation and then copies them back to the other volume. Is there a way for me to prevent me being the middle man on this copy? Thanks Scott S If you can get to the server console, you can use Toolbox for this, load it on the console and you get some dos-like commands. -- Andrew C Taubman Novell Support Forums Volunteer SysOp http://support.novell.com/forums (Sorry, support i...

Copy files from server to server...how?
I've heard "try toolbox" and to tell you the truth I'm a little fuzzy on that one. I can login, great... I've heard that cpqfm.nlm can do this. What is the nomenclature for the server to want to copy to? Thanks, Troy On Wed, 16 Aug 2006 11:01:13 -0700, Troy H <in2theabyss@gmail.com> wrote: > I've heard "try toolbox" and to tell you the truth I'm a little fuzzy on > that one. I can login, great... The toolbox help file is a little bit brief, but since most of the commands are clones of common CLI stuff (move, copy...

File copy server to server ?
Does anyone know of a util that will allow for a direct server to server file or folder copy? If you use explorer on a windows workstation, the file traffic must past through your workstation, or at least, be controlled by your workstation. I'd like something that you could set, and then shutdown your windows box even, if you had to. The only thing I know of is toolbox, at the server itself, but that requires it be loaded on both servers. Ncopy is another example of where you must leave the window open. We semi-frequently have to transfer hundreds of megabytes of user folders f...

Copying files from server to server
--____UXFLEXDGVUTPRTDRYJYN____ Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; modification-date="Fri, 7 Dec 2006 06:48:39 -0600" hello all, I want to run a cron job that will copy an entire directory from server to = server. I have been trying to use Toolbox 2.17 to do it, only it does not = work. I have messed with the syntax and the only thing I can think of is = there is some sort of authentication issue. I can copy a directory from = volume to volume on the same server just fine. Can so...

copy files from the server to a temporary folder on the local machine
We would like to copy desktop applications from the server to a temporary folder on the local machine and run passing parameters. Is this possible? > {quote:title=DENNIS TELL CARLOS wrote:}{quote} > We would like to copy desktop applications from the server to a temporary folder on the local machine and run passing parameters. Is this possible? At face value, this would not be possible; browsers do not allow access to the local machine directly by the server... too much of a security risk. You might accomplish it if you create an ActiveX control, though. Scott is correct tha...

is SAMBA server a ftp server, if not what is the name of ftp server in linux?
Title explains it all, I want to configure and use a ftp server :) -- yasar11732 ------------------------------------------------------------------------ Samba allows for file sharing with Windows system. You designate folders which you want to appear as shares to Windows clients on a network. It also includes tools to allow your Linux box to access windows shares on windows systems. If you want to set up an ftp server you might want to look at vsftpd and proftpd - both are available in Yast. There are many tutorials on installing these. Cheers, Lews Therin ...

FTP a file to a FTP server with .NET code
    Hi,I want my web app to be able to upload a user submitted file via FTP to another server.  I'm checking out components and they seem way out of price range for me ($399+)  Isn't there some simple source code in .NET available ?   Or maybe somebody knows a good, reliable, cheaper component ?Any help much appreciatedthanks,mike123 See the Google search results for c# ftp upload, more specifically http://www.csharphelp.com/archives/archive9.html. RyanRyan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question   ...

Copy file from server A to server B
Hi, My aim is to have the server copy a file from one server to the other via a batch file using toolbox. I am trying to copy the dsrepair file created in wftech3/sys:/system/dsr_dib/00000000.$DU to wftech1/data:/edirbak/ I will make a weekly backup of this file but would like to setup a batch file to run this...i have tried to use toolbox, but am not sure if i am using it correctly i keep getting a error message: TOOLBOX: Authentication failed to wftech1 NWDSLogin error: Check username [-601] LoginToFileServer error: Unknown server or username [252]...

Copy file from server A to server B
Hi, My aim is to have the server copy a file from one server to the other via a batch file using toolbox. I am trying to copy the dsrepair file created in wftech3/sys:/system/dsr_dib/00000000.$DU to wftech1/data:/edirbak/ I will make a weekly backup of this file but would like to setup a batch file to run this...i have tried to use toolbox, but am not sure if i am using it correctly i keep getting a error message: TOOLBOX: Authentication failed to wftech1 NWDSLogin error: Check username [-601] LoginToFileServer error: Unknown server or username [252]...

Access local server(LAN Server) from Web Server(Web Application Server)
Hello All I have a local server for my LAN and a Web server(at remote location).Is it possible to access my Local Server from my Web Server ? Thanks MS  ...

Bulk Copy between remote server and local server
How to perform Bulk Copy of a table from a Remote SQL Server 2000 to Local SQL Server 2000? I need to do this programmatically. Can't use DTS Import/Export Wizard. Need the steps of Bulk Insertion.With Regards,Prodipta Mondal.Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread. Is this a one time thing or an operation you'd like to perform on some regular basis?  I only ask because my approach would definitely be different based on that.Chris StewartCompiledMonkey.com This will be perform...

how to copy a line of a local server to a remote server?
how to copy a line of a local server to a remote server? Thanks Can you provide more details as to what you are trying to do. Karl <v.gouy-dion> wrote in message news:3f252a3d.6056.846930886@sybase.com... > how to copy a line of a local server to a remote server? > Thanks ...

Unable to copy large files from server to server
Running OS 6.5sp4. OK, TBX will not copy files server to server. The older Toolbox will not copy either under this case. The files we are trying to copy are zmg image files of 4.9GB and larger. NSS volume to NSS volume. We have tried the above utilities with no success. We have also tried Microsoft copy command and NWcopy with no success. What are we doing wrong? I'm not sure if you have the latest Novell client on your w/s, but there was a time where it had a 2gb limit. <awk@readingsd.org> wrote in message news:9832h.23213$0h7.13781@prv-forum2.provo.novell.com... &...

Web resources about - Copy files from local server folder to FTP server - asp.net.getting-started

Server farm - Wikipedia, the free encyclopedia
A server farm or server cluster is a collection of computer servers usually maintained by an enterprise to accomplish server needs far beyond ...

CRTC Issues First-Ever Warrant To Take Down Toronto-Based Malware Server 4
TORONTO — The CRTC has issued its first warrant under the federal government's anti-spam legislation to take down a Toronto-based malware server ...

Windows Server 2016 moving to per core, not per socket, licensing
Windows Server 2016, not likely to arrive until the second half of next year, is going to shake up the way Microsoft licenses its server operating ...

Intel Rising: Server Stronger Than Ever, Says JMP; Here Comes Apple?
... stock to Market Outperform from Market Perform, assigning a $45 price target, righting that the company will strengthen its hold on its server ...

Server shipments, vendor revenue go up in Q3 2015
In the third quarter of 2015, worldwide server shipments grew 9.2 percent from the third quarter of 2014, while vendor revenue increased 7.5 ...

Bloodborne servers taken down for 'emergency maintenance'
An exploit and other "serious issues" have been detected.

PR Guru Working For Clinton Server IT Firm Donated To Hillary’s Campaign
PR Guru Working For Clinton Server IT Firm Donated To Hillary’s Campaign

Inventec achieves major improvement in server orders for 2017
With Intel expected to launch its next-generation server platform Purley in the second half of 2017, vendors such as Hewlett-Packard (HP), Dell ...

Server Files Sexual Harassment Complaint Against Pigalle Restaurant
... restaurant Pigalle is being accused of sexual harassment by a waitress , who says that management implied her jeans were "too much." The server ...

HPE, Dell Stay Atop Growing Global Server Market
Demand for rack systems and growth of hyperscale data centers help drive growth of x86-based systems, according to IDC and Gartner analysts. ...

Resources last updated: 12/5/2015 11:51:39 PM