Write And Read .txt files from FTP with C# - c#

Is it possible to write a txt file on ftp (not upload a file to ftp!) Directly writing a txt file on ftp server) and read from a file on a ftp (not download a file from ftp!) Directly read from a txt file on ftp server? I searched but ı found upload a file and donwload a file with FtpWebRequest class. Note: FTP server uses credentials.

No, it is not possible.
The FTP protocol described in RFC 959 doesn't have any means to achieve what you want.

No, as far as I'm aware, your only option is to download or upload the file. I guess you could short-circuit it a bit by only downloading the file until you got to the part you needed, then aborting. But the whole purpose of FTP is to upload/download FILES, not content.

It's possible with help of third-party virtual file system driver which should be installed in system. There exist third-party applications which let you see the remote FTP location as a virtual disk on your computer. Once the remote FTP location is mounted this way you can use regular file I/O methods to read and write those files. You can create such application as well (not a rocket science with right tools).

Related

How to serve files stored in FTP space

My ASP.Net MVC application allows you to download files that are stored in a repository accessible via FTP.
I would need to implement the best strategy to serve these files to the client. I could implement a method that downloads the file from FTP and then serves the file through FileResult ... but clearly it does not seem the best way at all (especially in the case of large files the client should first wait for the application to download the file and then wait a second time for the time necessary for the download).
Any indication or help will be appreciated
If the web server can only access the files over FTP, then that's the way to go.
If the files are on a different server, your web server needs to download them from there (either entirely or streaming) before it can serve them to its HTTP clients.
Alternatively both servers could share the same file location, either by attaching the same (virtual) disk or through another network protocol such as NFDlS, SMB, ...

How to verify that an SCP file upload was successful

I've been given an assignment to use SCP to upload a file to a Secure FTP Server (I'm doing this using Workflow Foundation activities). I can upload the file OK, but I need to do some sort of validation to make sure that the file is, in fact, there.
Any ideas ?
Thanks,
Chew
I've solved this type of problem before by:
uploading the file to the server.
downloading it as a different file name.
running a local comparison of the two files.
A script to do this is relatively easy to set up.

How to map an ftp share folder to a local drive using C#?

How do I map an ftp share folder to a local drive using C#? Is there any class library available for this?
I need to achieve the same functionality as NetDrive(http://www.netdrive.net/) offers using FTP ?
Maybe you can leverage someone else's work and get a headstart. The makers of NetDrive for instance offer an SDK - not sure what that requires / costs, however. But it might be worth an inquiry, no?
And maybe, if you combine this approach to define a remote FTP site as a Windows network share, and then use this code in C# to mount a network share as a drive, you might get your job done :-)
It's a very tall order - if you actually want a local drive, e.g. X:\, to access an FTP site, you'd surely need to write a driver. Not an easy task.
If you want it to simply appear in Windows Explorer somewhere - you can use the shell extension as Marco's answer suggests. But don't expect to be able to treat it like a regular drive.
To create a virtual drive or a folder on existing drive and expose remote FTP server contents that way you need a filesystem driver. Or use can use our Callback File System (CBFS) product which lets you write the code in user-mode and includes a pre-created filesystem driver. CBFS includes a sample, SFTPDisk, that does exactly what you need, but with SFTP protocol (SFTP is not FTP but SSH File Transfer Protocol).
Note, that in FTP there's no function to upload a block to the middle of the existing file. This makes some file write operations trickier than with SFTP or local filesystem - you may need to cache the whole file and upload it asynchronously when it's closed by the client.
There's a project in C# to use an FTP folder as virtual drive -> http://amalgam.codeplex.com/ (it uses dokan).
There's a freeware program that does the same thing -> http://www.ferrobackup.com/ftpuse/

Uploading files to Linux server from Windows C#

I have to write a C# program that only needs to work on Windows. It needs to allow the user to select a file to upload. That file will be uploaded to a folder on a remote Linux server. I know the username, password, and url for this Linux machine. Does anyone know how I go about connecting to the server and then uploading the file to it in a C# desktop application?
If you're going to upload over FTP, the FtpWebRequest should do the trick:
http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx
So I came up with this answer before looking at the first response (David's). Interestingly, we came up with the same solution! An ftp upload was what I was looking for. I completely forgot about FTP.
MSDN also has this web page for a more succinct how-to:
http://msdn.microsoft.com/en-us/library/ms229715.aspx

How to correctly write dynamic files to an FTP server?

I'm using C# and i have written a locally installed application that dynamically generates files which need to be on an FTP server.
Do i generate them to disk then upload them to the FTP server? or is there a way to open a stream to an FTP server and write the files directly?
Check the code sample I gave in this answer, doesn't rely on writing to files. It's not SQL specific and was just a suggestion on how to use SQL CLR integration assemblies to upload output from sql queries to an FTP server. The for loop in the method is just to demonstrate writing to the FTP stream. You should be able to rework to you needs:
How to write stored procedure output directly to a file on an FTP without using local or temp files?
You should follow the class:
System.Net.FtpWebRequest
You will see that its arguments are streams and you can send data to them from any source.
When seaching for .Net capabilities you should be aware of the object browser for visual studio acessible in:
View > other windows > object browser
Is supplies a search over all known assembly .Net objects.
The better way is to save file locally, and upload it later, since there could be problems with upload process.
Since you are using c# I'm thinking maybe you are in a Windows Env. Something I know little about :)
If you are dealing with a unix env, you could just pipe your output thru SSH, which would also take care of encryption overhead.

Categories