.NET FtpWebRequest Not Returning DateTimeStamp Or FileSize?
Jun 4, 2010
I'm using FtpWebRequest to connect to an FTP server and I can use WebRequestMethods.Ftp.ListDirectoryDetails to list the directory details fine. However the response from the remote server has day, month and time but not year:
-rw-rw-rw- 1 user group 949 Jun 2 08:43 Unsubscribes_20100602.zip
-rw-rw-rw- 1 user group 1773 Jun 1 06:48 export_142571709.txt
-rw-rw-rw- 1 user group 1773 Jun 1 06:50 export_142571722.txt
-rw-rw-rw- 1 user group 980 Jun 1 06:51 export_142571734.txt
This is required for the application I'm writing so I tried to use WebRequestMethods.Ftp.GetDateTimestamp to get the datetimestamp for each file but the response is always empty. No exception is thrown.
try
{
FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(path);
ftp.Credentials = new NetworkCredential(_ftpUsername, _ftpPassword);
ftp.Method = WebRequestMethods.Ftp.GetDateTimestamp;
try
{
Stream stream = ftp.GetResponse().GetResponseStream();
StreamReader sReader = new StreamReader(stream);
return sReader;
}
catch (Exception exp)
{
throw new Exception(String.Format("An error occured getting the timestamp for {0}: {1}<br />", path, exp.Message));
}
}
I have setup my server computers iis to have a ftp site on port 21 and transfering files works great. But I want to add ftp to a hosted site I got on the server and it's here where I get the problems with connecting. when I try to connect through the command promt I get unknown host error. I have changed the port and open it up in firewall. and even if I could connect how can I decide what folder I want to upload to?
i am using upload control to upload files on server i am using VS2005 framework 2.0i have given a limit of 50 MB filesize for uplaodng .the file uploading takes place properly but1) the harddisk space problem. so how do i zip the file in code when the file is selected for uplaoding & when the user clicks view . it shld be unzipped & displayed to teh user2) i need to display a limit of 50 mbif the size is above 50 MB , the code shld dispaly a mesage & exitsubi need to use the code in the save click of a button3)if i need to uplaod a file of max 50 mb wht sgld be teh execution time out that needs to be specified in webconfig taking into consideration the system speed, the page shldnot blank out
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm"); request.Method = WebRequestMethods.Ftp.UploadFile; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com"); // Copy the contents of the file to the request stream. StreamReader sourceStream = new StreamReader("testfile.txt"); byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse)request.GetResponse();
For uploading images and songs to the server. But the file is getting corrupted on upload. Normal upload is getting error due to security reason and access issues.
Had to dwell on to ftp. But in this case, file is getting corrupted.
Invalid URI: Invalid port specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.UriFormatException: Invalid URI: Invalid port specified.
We have a web project that contain its business methods in a class library project called "Bll.dll" some methods of Bll.dll return List<> ... from a source - that i don't remember now - told that returning Collection<> is better than returning List<> Is it a valid ? Note that i don't make any process on values returned from BLL methods .. just view it in a web page
I have a form with 10 file inputs. They can contain 10 random files with random sizes. If I send these files to ASP.NET server with this code:
var count = HttpContext.Current.Request.Files.Count; var TotalSize = 0; for (int i = 0; i < count; i++ ) { HttpPostedFile postedFile = HttpContext.Current.Request.Files.Get(i); TotalSize += postedFile.ContentLength; }
And as you can see I didn't save the files on the server, will this code just calculate the summary of files without need to receive the whole file from the client (And therefore it would be very fast)?
I have a simple asp.net form that has a textbox that collects phonenumbers to send SMS messages. If I bypass the form and hardcode the numbers using the following format:
"2133211234",#1233211234"
the code works fine. However when i try to use this same format using my form, the sms will ONLY send to the first number. I have a feeling i'm missing out on some property on my form that will accept all of the values. how how i can add some lines of code that will allow users to enter numbers like this:
3123211234,4123212344 and have it converted to the format above when the number is submitted?
I have a function inside a utility class which returns the current session User ID. It throws object reference not set to instance of object ? How do I check it for null & remove this error ?
public static string GetSessionUserID { get { string userID = ""; if (System.Web.HttpContext.Current.Session["userID"].ToString() != null) { userID = System.Web.HttpContext.Current.Session["userID"].ToString(); } if (userID == null) { throw new ApplicationException("UserID is null"); } else return userID; } }
How is it possible to return some kind of list from a WCF service, this the method in my WCF service.
My interface:
[OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Locations")] IList<Location> GetLocations(); public IList<Location> GetLocations() { Pazar.Data.Repositories.LocationRepository locRepository = new Pazar.Data.Repositories.LocationRepository(); return locRepository.GetRootLocations().ToList<Location>(); } and this how my GetRootLocations looks like, It returns IQueryable, I wonder if I can maybe return IQueryable from my WCF service? public IQueryable<Location> GetRootLocations() { IQueryable<Location> locations = GetAll().Where(p => !p.ID_Parent.HasValue).OrderBy(p => p.Sequence); return locations; }
I have created alot of stored procedures in my application that return the result of a query in a datatable object. I never use a dataset. Why would I ever use a dataset over simply returning the result of a query as a datatable object?
I have a problem with getting jquery to retrieve results from a WCF service. I am hosting the WCF service within IIS and when I attach the debugger to this process I can see that the code is processed successfully. However, when it hits the callback within jquery there is no data??
I have set up a trace on the wcf service and there are no errors. It just seems as though the data is lost after the wcf service method completes.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class EcopsService : IEcopsServiceContract { #region IEcopsServiceContract Members public string Echo(string echoThis) { return string.Format("You sent this '{0}'.", echoThis); } #endregion }
My SQL query joins on multiple tables, and because of this it is displaying multiple results. I know about SELECT DISTINCT, but one of the fields ('Account.Name') is occasionally different, so it treats this record as a new row. Here is my SQL:
I have a call to a function in my business logic area. It should be returning a true.
[URL]
This url above is the culprit. The code doesn't seem to like the .asp type of file. I wonder why this is the case. I get a true response for a html or php type of file. The above returns false. Does anyone know why?
[Code]....
[Code]....
Public Shared Function MakeURL(ByVal url As String) As String Return "http://" & url.Replace("http://", "") End Function
I'm saving military time into the database. Then I need to pull this data back out of the database. To get just the time without the date I can do this: String.Format("{0:T}", pullsaved.First.timeValue) But this returns a six digit time, e.g. 100000 (HHmmss). But I want it to return just HHmm (1000). I tried the following, but it didn't work. DateTime.ParseExact(String.Format("{0:T}", pullsaved.First.timeValue), "HHmm", CultureInfo.InvariantCulture)
I need to call a popup page with terms and conditions (modal if possible), and once the user ticks the acceptance tick box in T&C popup and closes popup page I need to get the tick box value back into the calling page. How can achieve this via code?
I am having an issue getting a value from a ModalDialog back to the page that called it so I can change the alternate text of an image based on what is entered in the textbox.Any thoughts on how to properly return the value and use it?Provided below is my code related to this.Main Page (This is a Content Page!) on PageLoad
I have an asp.net web application that use FormsAuthentication. Now, the application has a WCF Service that need to use Basic Authentication. So, I need to return the 401 status code, but everytime it's picked up by asp.net and redirecting me to the login page.How could I disable this feature and finally being able to throw a 401 without intervention from the FormsAuthentication module?