|
having problem to translate from WinForm to Windows-CE C# program - FTP transfer
i have this code for transfer from Local computer to FTP server
its work excellent on WinForm, i must have this on Windows-CE and it dosnt work
the code:
string MyFile = @"d:\PC.sdf";
string url = "ftp://127.0.0.1/PC.sdf";
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
using (Stream reqStream = request.GetRequestStream())
{
int count = 0;
byte[] buffer = new byte[100];
using (FileStream file = new FileStream(MyFile, FileMode.Open))
{
while ((count = file.Read(buffer, 0, 100)) > 0)
{
reqStream.Write(buffer, 0, count);
}
}
}
in WinCE there isnt FtpWebRequest or FtpWebRequest
i think that i need to use OpenNetCF ????
can i get any C# sample code for this ?
modified on Friday, August 12, 2011 6:08 AM
|
|
|
|
|
Firstly, always use the code block widget when posting code samples - it preserves the formatting and makes it easier to read. (you can edit your question and add it)
Secondly, "it dosnt work" isn't particularly helpful - what does it do that you didn't expect, or not do that you did? Was there an error message?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
We had a module that could log to an Oracle (and file if you wished), but my boss now wants to use the MS Enterprise library, where Microsoft of course only provides information on how to log to SQLServer. I searched on the net and found an article about how to log to Oracle, but unfortunately it is outdated (still uses Lib 2.0 and we're on Lib 5.0) Has anyone have any experience with this, because I'm stuck on this a little.
I did find a workaround by modifying the existing dll we had, attach it to the Enterprise Lib and use that one to write to Oracle, but personally I feel it is slow and the format of the log is dreadfull.
Any pointers on this would be very helpful.
thanks.
V.
|
|
|
|
|
Hello.
If I have an uint value, that may be differnt lenghts, how would I create a new int from it at a fixed length, or better still select specific digits.
e.g
uint begin = 293844; OR 29388493
uint shorter = 2938;
OR
uint select = 2339 (skip every other digit).
I basically want a new value from a uint that could be different sizes, and ensure the new value is a fixed length in size.
I have a feeling I need to use bit wise operations, but still dont understand them fully.
Thank you in advance for any advice.
Kind Regards,
Stephen
|
|
|
|
|
stephen.darling wrote: I have a feeling I need to use bit wise operations
Looks to me like you should be looking at string operations. Convert your number to a string, then play with characters or substrings. Convert back at the end if you need to. Bitwise operations don't match up with decimal digits.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Peter_in_2780 wrote: Convert your number to a string, then play with characters or substrings. Convert back at the end if you need to
Wow! Never even thought about doing it that way!
Thank you,
Stephen
|
|
|
|
|
You could do this with bitwise math if you also throw in a lot of divisions and multiplies by 10..
But it will be a mess.
Why are you working with decimal digits anyway?
What is the actual problem you're trying to solve, maybe it could be done with hex digits instead?
|
|
|
|
|
A uint is always the same size (32 bits).
What you're trying to do is string manipulation of a decimal number, quite a strange thing to do but probably best done on the string representation.
|
|
|
|
|
I'm not sure how do you want to get the second sample. In the first case, string manipulation is a way to go. Other, more math (and probably faster) solution is to get a length of begin and then divide it by 10^(length-4). Ot sth like (not tested):
uint shorter=begin;
while(shorter >= 10000) {
shorter /= 10;
}
Greetings - Jacek
|
|
|
|
|
Thank you everyone. If I explain my requirements maybe it will help.
I am generating a serial number in the following format:
00000-00000-00000-00000
I pass in two values into the serialGenerator class
int ProductID
int ProductVersion
I then combine these into one int value, say for example 12345123
Then I get the hex byte array representing this value, and hash it.
I then take 2 bytes of the hash from predetermined positions.
Then, I need to perform the bitwise so that I take a fixed part of teh new int value, which will always be 5 digits (first part of the serial number)
Generating the rest I have figured out.
Hope this clears things
Regards,
Stephen
|
|
|
|
|
stephen.darling wrote: I then take 2 bytes
You can't get 293844 from two "bytes".
Largest unsigned value from two 8 bit bytes used to create a 16 bit value is 256*256=65536.
|
|
|
|
|
jschell wrote: You can't get 293844 from two "bytes".
Sorry, I meant two uint32 values...
Steve
|
|
|
|
|
I use the following code when closing a form:
protected override void OnClosing(CancelEventArgs e)
{
//Your alternate implementation
FormClosingEventArgs ce = e as FormClosingEventArgs;
if (ce != null)
{
switch (ce.CloseReason)
{
case CloseReason.ApplicationExitCall:
//Handle application exit call
break;
case CloseReason.FormOwnerClosing:
//Handle Form owner close
break;
case CloseReason.MdiFormClosing:
//Handle MDI parent closing
break;
case CloseReason.None:
//Handle unknown reason
break;
case CloseReason.TaskManagerClosing:
//Handle taskmanager close
break;
case CloseReason.UserClosing:
//Handle User close
break;
case CloseReason.WindowsShutDown:
//Handle system shutdown
break;
}
}
base.OnClosing(e);
}
However on one of my forms it just working, it used to work fine
I setup a new form but still no results, I set a breakpoint and it doesn't even hit it.
Can anyone help with this problem.
Any help will be appreciated.
Thanks in advance,
Michael
|
|
|
|
|
I find your code confusing for two reasons
1) you override OnClosing instead of the preferred OnFormClosing method. Are you targetting .Net 1.1?
2) you cast the CancelEventArgs to FormClosingEventArgs. Surely this will never work and the resultant value will always be null.
The breakpoint problem might be explained by the cautionary note regarding the Application.Exit method in http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onclosing.aspx[^].
|
|
|
|
|
i have FTP server in my computer (Windows-7) called MyFTP
i have thit code to transfer from local directory to FTP server
this code work excellent
string MyFile = @"d:\Test.txt";
//string url = "ftpUrl/FileName";
string url = "ftp://127.0.0.1/Test.txt";
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.UploadFile;
//request.Credentials = new NetworkCredential("user name", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
byte[] buffer = File.ReadAllBytes(MyFile);
using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(buffer, 0, buffer.Length);
}
and now i need to to transfer from FTP server to local directory in my computer
how to do it ?
modified on Thursday, August 11, 2011 5:11 PM
|
|
|
|
|
Hello Experts,
I would like ask how I will alow my client(the one browsing the internet) to upload the file into my web server. I set up my web application using the abyss web server so that I can host the website to my local machine, and for the FTP I use filezilla.
Below here is my code but it's only working in my local machine.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Net;
using System.Web.UI.WebControls;
namespace ftpPractice
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void uploadFileUsingFTP(String CompleteFTPPath, String CompleteLocalPat)
{
try
{
FtpWebRequest reqObj = WebRequest.Create(CompleteFTPPath) as FtpWebRequest;
reqObj.Method = WebRequestMethods.Ftp.UploadFile;
reqObj.Credentials = new NetworkCredential("Akosidan", "newbie");
FileStream streamObj = File.OpenRead(CompleteLocalPat);
byte[] buffer = new byte[streamObj.Length];
streamObj.Read(buffer, 0, buffer.Length);
streamObj.Close();
streamObj = null;
reqObj.GetRequestStream().Write(buffer, 0, buffer.Length);
reqObj = null;
lblMessage.Text= "File Uploaded Successfully :)";
}
catch (Exception error)
{
Response.Write(error.ToString());
}
}
protected void cmdUpload_Click(object sender, EventArgs e)
{
uploadFileUsingFTP("ftp://localhost/recieveSample.txt", "C:\\someUsers\\someFolder\\Desktop\\sample.txt");
}
}
}
Comments,suggestion or recommendation is so much appreciated.
AkosiDAN <- newbie
|
|
|
|
|
|
Hello,
Thanks for the link. Now I don't need anymore 3rd party ftp server just to transfer file
Thanks again,
DAN
|
|
|
|
|
Hello,
I have an activeMQ broker and .net(c#) application that send and consume message without problem.
Now, I want to add some security to broker to avoid anyone else send or consume my messages.
So, I add simpleAuthenticationPlugin with username/password in AMQ configuration file, now in .net client I can't send messages because username/passw should be provided.
Until now all is ok, the problem is I dont found where to supply this information from code.
I can't set it in CachingConnectionFactory or SimpleConnectionFactory, it is not allowed, I dont find any other type of ConnectionFactory available in Spring.Messagin.Nms namespace I could use.
So I need some hint from any of you.
spring conf file is very simple:
<object id="ActiveMqConnectionFactory" type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ">
<property name="UserName" value="usertest"/>
<property name="Password" value="passwordtest"/>
</object>
<object id="ConnectionFactory" type="Spring.Messaging.Nms.Connections.CachingConnectionFactory, Spring.Messaging.Nms">
<constructor-arg index="0" ref="ActiveMqConnectionFactory"/>
<property name="SessionCacheSize" value="10"/>
</object>
<object id="NmsTemplate" type="Spring.Messaging.Nms.Core.NmsTemplate, Spring.Messaging.Nms">
<constructor-arg index="0" ref="ConnectionFactory"/>
<property name="MessageConverter" ref="SimpleMessageConverter"/>
</object>
and in c# code I just use NmsTemplate as:
this.NmsTemplate.ConvertAndSend(msg);
Thanks in advances
|
|
|
|
|
Hi everybody!
I want to know if it is possible to get the USB port current value when I plug the device in it. The value should be get programmatically using C#. The second parameter I need is USB save power mode. The correct name of the property in the device manager is "Allow the computer to turn off this device to save power".
I managed to detect the device (if it is connected or disconnected) and read data from it correctly. Do these two properties belong to USB device or to USB port?! WinUSB Api did not give me clear answers to my questions.
Thanks!
|
|
|
|
|
Ok, this is probably a very basic question, but how would I go about creating the following (bear with me. I'm new to oop):
Lets say I'm in the automotive industry and I build a c# class called "Cars". Within this class, I have 2 properties:
-Model
-Year
So I can call them via Cars.Model & Cars.Year via code like this:
public class Cars
{
public string Model { get; set; }
public string Year { get; set; }
}
So far, so good....HOWEVER....now, I want to do a sub-property of Model, called Color. I would want to call it with something like this:
Cars.Model.Color = "green";
How would I create this "Color" property so that it becomes a sub-property of "Model"?
Thanks
|
|
|
|
|
You give Model a type that has a property called Color
|
|
|
|
|
I don't think somebody likes us giving this poster answers.
|
|
|
|
|
So it would seem..
Oh well, we probably got more upvotes because of it
|
|
|
|
|
I have been repeatedly asking to make comments mandatory for downvotes. I understand that the voter may put some garbage in the comments just for the sake of it. But it would help us to identify the trolls and banish them. (It can also help Chris to delete those downvotes).
|
|
|
|