ftp - c# code to get space used on server

- we simply want a piece of code that will find out how much space has been used on an FTP server.
 - we have had a junior c# developer writing the code but is now having problems.  It seems to work intermittently with the code he has written (enclosed below)
 - it works fine when we have small numbers of files on the ftp server but starts to go wrong when there are lots (8 gig, 1000 files)
 - it seems to work more of the time when we put Thead.sleep statements in and it works consistently when we are stepping through the code in Visual studio.
 - it may be related to an asyncronous/syncronous problem
 - there may be a much easier way to do it
Any help appreciated

//returns the amount of space used by files currently stored in the users' directory
        private long getSpaceUsed()
            //StringBuilder result = new StringBuilder();
            ArrayList sizes = new ArrayList();

                FtpWebRequest sizeCheck;
                sizeCheck = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpAddress + "/" + this.uid));
                sizeCheck.UseBinary = true;
                sizeCheck.Timeout = 999999999;
                //sizeCheck.KeepAlive = true;
                //sizeCheck.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
                sizeCheck.Credentials =  new NetworkCredential("kbackupc", "32backup10");
                sizeCheck.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                FtpWebResponse response = (FtpWebResponse)sizeCheck.GetResponse();
                StreamReader read = new StreamReader(response.GetResponseStream());
                    string line = read.ReadLine();
                    string[] line2 = line.Substring(1).TrimStart().Split();
                    string size = line2[18];
                    while (read.Peek() >= 0)
                        line = read.ReadLine();
                        line2 = line.Substring(17).TrimStart().Split();
                        size = line2[0];

                //result.Remove(result.ToString().LastIndexOf('\n'), 1);
            long sizeServer = 0;

            foreach (string s in sizes)
                if (s != "")
                        sizeServer += Convert.ToInt64(s);
                        sizeServer += 0;

            return sizeServer;
9/9/2008 12:43:46 PM
asp.net.free-for-all 9281 articles. 0 followers. Follow

1 Replies

Similar Articles

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

Could you please format your code in a way that is readable? The very last item on the menu bar (if posting via http) will allow you to format your source.



Visit My Blog http://www.mick-walker.co.uk
9/9/2008 12:58:36 PM

Similar Artilces:

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   ...

How to get new web app to use .NET 2.0 on Win2K server using .NET 1.1 as default framework?
I have .net framework1.1 and 2.0 on our server running win2K. i have existing applications that uses asp.net 1.1, i also have a new app that use ASP.net 2.0.  how can i set my new .NET 2.0 app to point to asp.net 2.0 without messing up my existing .NET 1.1 apps? To specify the ASP .Net version fro a web application, do the followingIn IIS Manager select the web application -> Properties -> ASP.Net TabSelect  ASP.Net version you want to use for the applicationRegards,PrashantDont forget to click "Mark as Answer" on the post that helped you. But I am running Win2K...

using GET of NET::FTP
get ($remote,$local,$where) is failing whenever i use the third arguement. here in this case my file to be downloaded from FTP is of size 5MB. 2Mb of it is downloaded, now when i am executing the get ($remote,$local,$where) with $where as 2MB(2048), get method is returning me nothing and download is getting aborted. can anybody plz help me out to solve this problem. ...

Keep getting..."Unable to get project file from server",when using vs.net
When trying to open any existing asp.net project in Visual Studio it keeps giving me the message above. It is also throwing an error when I create the project in the first place, it happens when a dos window is opened, the text in the dos window is running "Common Language Runtime Minidump Utility version 1.0.3705.0" and then VS craps out says there was an error and shuts down. I've re-installed the .net components and framework with no avail, and FrontPage extensions etc.. are all installed. I'm running XP professional and have installed IIS 5.1. This is driving me fec...

All, This is probably a much harder question than what should go in the "Getting Started" forum, but I am new and don't know where to put it. Anyways, I am currently developing an FTP class in VB.NET. It's kid tested, mother approved when trying to access an FTP Server on a Windows box meaning I can connect, run commands, upload and download a file no problem. My issues come when I try to use the same class with the same commands to access an FTP server on a UNIX box. I can connect and login just fine, but after that all my commands come back "500 'PWD': command not understood.". This is fo...

Getting a whole directory using Net::FTP
Hi, I would like to upload and download files to a Linux server from my Windows machine. So, I set out to write a little script that does just that. Uploading, it turns out, is no problem. I use an "opendir" statement to open the directory, then readdir to read its contents and then each file gets "put". This works and so, I thought, that's what I'll do for downloading files too. However, I don't seem to be able to open the remote directory. I get the message that the $dir cannot be opened ("Ik kan $dir niet openen!"). I added a snippe...

Problem in getting free space using GetDiskFreeSpaceExA
Hi All, I am using the following code in order to find the free space for the specified hard drive. I am getting some weird output by using this API. Could someone please help me in point out the issue. Here is my code String ls_total_bytes, ls_free_bytes, ls_used_bytes Double ld_total_bytes, ld_high_temp, ld_low_temp,ld_free_bytes,ld_used_bytes LARGE_INTEGER lli_caller, lli_total, lli_free ZeroMemory( lli_caller, 8 ) ZeroMemory( lli_total, 8 ) ZeroMemory( lli_free, 8 ) ...

Getting the file creation time using Net::FTP
Hi to All, Currently, I'm doing a script using the Net::FTP module, this script will just get all the files created on a particular date. The problem right now (which I'm stuck) is that some files don't have creation date and time included in their filename so there's no way I can get those files by not specifying the creation time. Base on the man page for Net::FTP, mdtm() returns the modification time of the file but it did not return anything. Here's a snippet: $file = "sample_file"; $ftp = Net::FTP->new("hostname"); $ftp->logi...

use VB.net to download file from FTP server
I want to write a VB problem that can download files from my ftp server. how do I do it? any free component to download? thank you. well, i cant suggest a free component.  However, the .Net framework has a number of classes for getting files from HTTP servers.  I don't know about a FTP site but this is what works for me. Dim wc As New System.Net.WebClientDim DLAddress As String = "http://YourSiteName.com/download/" + ProgramName + ".msi"Dim DLLocation As String = "c:\SomeDirectory\" + ProgramName + ".msi"Trywc.DownloadFile(DLAddress, DLLocation)MessageBox.Show("There is an ...

UNIX file system free space, used space, total space
Anyone have an idea about getting UNIX file system free space, used space, total space numbers without having to resort to something like the following ( which gets the percent of used space for a command-line supplied file system name stored in the variable ${file_sys} ): $per_used = `df -k | grep " ${file_sys}\$" | awk '{print \$5}'`; > Anthony (Tony) Esposito > Senior Technical Consultant > Inovis(tm), formerly Harbinger and Extricity > 2425 N. Central Expressway, Suite 900 > Richardson, TX 75080 > (972) 643-3115 > tony.esposito@ino...

Incorrect used/free space graph in iFolder client and server
Don't understand why on the iFolder server a user account space says *USED 0GB* but when she runs the client or the web it says 1.2GB used.!! She deleted her data a while ago to start a fresh. The data was deleted from the server by the user " Revert to a normal folder and then delete from the server". But when she runs iFolder client it says 1.2GB in used and no other option to download if the client thinks there is data on the iFolder server. Un-installed the client completely but it still thinks data attached to her account when the server says she hasn'...

How to get windows log-in user name using vb.net code?
Hi, I built an asp.net web application on our companies HR system so that recruitors can post jobs. Is there a way to get the windows logged in user name using vb.net code? This user name is using for tracking who posted the job. Thank you.   Windows Authentication provides some options, as does forms authentication.  See if you get what you need through User.Identity.Name.  Take a look at: http://www.15seconds.com/issue/020220.htmhttp://aspnet.4guysfromrolla.com/articles/120705-1.aspx JeffPlease: Don't forget to click "Mark as Answer" on the p...

get data from a html textbox and use that information in VB.NET code
Hello! Can anybody tell me how to get data from a html textbox and use that information in the coding of VB.NET. Actually I am working in SALT just like Bind Element Example, I would like that user speaks the data in and I use this data to be entered in a oracle database using VB.NET coding. Right now the data is not forwarding to the click event of aspx button from the html textbox. Can any body help me soon and early. I will be grateful. Haroon is the text box an asp:textbox or a plain old html input control? If either make sure that it is dimensioned in the codebehind if that i...

Local Client-side printing using server vb.net code?
Hi,Rather than use the window.print() command which is just a form dump.  I want to use vb.net code to do this as it has all the features necessary.I came across this useful article from developers.com.  http://www.developer.com/net/net/article.php/3102381However, when I run this it throws an exception because there is no default printer attached to the server.  Of course I don't want to print server side - thats no good.  But print client side.  The users would print to whatever print queue on the network they have connected to their own pc.I thought ...

Free .Net and Sql Server Training Videos for Developers just getting started
I figured since this is the Getting started forum I would mention a great .Net training video site with some free videos.http://www.TechnicalVideos.netThanksMike James...

Web resources about - ftp - c# code to get space used on server - asp.net.free-for-all

X.Org Server - Wikipedia, the free encyclopedia
X.Org Server refers to the X server release packages stewarded by the X.Org Foundation , which is hosted by freedesktop.org , and grants public ...

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 ...

Attack floods Internet root servers with 5 million queries a second
Enlarge (credit: rootservers.org ) Early last week, one of the most vital organs of the Internet anatomy came under an unusual attack. On two ...

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 ...

Facebook releases design for its souped-up A.I. server, 'Big Sur'
Facebook is releasing the hardware design for a server it uses to train artificial intelligence (A.I.) software, allowing other companies exploring ...

Former Intelligence Chief Calls ‘Top Secret’ Info on Hillary’s Server ‘Unreal’
Former Intelligence Chief Calls ‘Top Secret’ Info on Hillary’s Server ‘Unreal’

Facebook, Google server outsourcing strategy change expected to impact profitability for ODMs
Facebook is planning to add Wiwynn, a server subsidiary of Wistron, as a new datacenter server supplier, joining its primary supplier Quanta ...

Facebook Open Sources Its 'Big Sur' AI Servers
The company hopes to accelerate innovation around deep learning by contributing the GPU-based system designs to the OCP.

Sources: Review affirms Clinton server emails were 'top secret,' despite department challenge
Sources: Review affirms Clinton server emails were 'top secret,' despite department challenge

Update: NFL says server power issue, not tablet glitch, caused Microsoft Surface outage on Monday Night ...
... NFL says the problem wasn’t with the tablets themselves. An NFL spokesperson tells GeekWire the problem stemmed from “the power to the server ...

Resources last updated: 12/16/2015 12:47:01 AM