|
You can't do it directly via the .NET FTP command. What you will have to do is work around this using something like this:
[DllImport("wininet.dll")]
private extern static IntPtr InternetConnect(IntPtr internet, string host, short port, string username, string password, int service, int flags, IntPtr context);
[DllImport("wininet.dll")]
private extern static bool FtpCommand(IntPtr connect, bool expectResponse, int flags, string command, IntPtr context, out IntPtr ftpCommand);
[DllImport("wininet.dll")]
private extern static bool IntPtr InternetCloseHandle(IntPtr connect);
public static bool ChangePermission(string uri, string folder, string userName, string password)
{
IntPtr context = IntPtr.Zero;
IntPtr ftpCommand = IntPtr.Zero;
IntPtr open = InternetOpen("Portal", 1, null, null, 0x10000000);
IntPtr connected = InternetConnect(open, uri, 21, userName, password, 1, 0x08000000, context);
if (!FtpCommand(connected, false, 0x00000001, "CWD " + folder, context, out ftpCommand)) return false;
if (!FtpCommand(connected, false, 0x00000001, "SITE CHMOD 775 theFile.txt", context, out ftpCommand)) return false;
bool connectedclose = InternetCloseHandle(connected);
bool openclose = InternetCloseHandle(open);
return (connectedclose && openclose)
} Note that I've just typed this out into the editor here. There may be a minor syntax error or two, but this should give you the idea.
|
|
|
|
|
Awesome, Thanks! I'll give it a go and report back. It looks like I'll need to bring in the InternetOpen procedure from wininet.dll as well.
|
|
|
|
|
No success yet. With the following code ChangePermission returns a false value every time. The file I'm adjusting permissions for is located in the root directory. I'm kind of learning as I go so there's a good chance I missed something obvious.
[DllImport("wininet.dll")]
private extern static IntPtr InternetConnect(IntPtr internet, string host, short port, string username, string password, int service, int flags, IntPtr context);
[DllImport("wininet.dll")]
private extern static bool FtpCommand(IntPtr connect, bool expectResponse, int flags, string command, IntPtr context, out IntPtr ftpCommand);
[DllImport("wininet.dll")]
private extern static bool InternetCloseHandle(IntPtr connect);
[DllImport("wininet.dll")]
static extern IntPtr InternetOpen(string lpszAgent, int dwAccessType, string lpszProxyName, string lpszProxyBypass, int dwFlags);
public static bool ChangePermission(string uri, string userName, string password, string fileName)
{
IntPtr context = IntPtr.Zero;
IntPtr ftpCommand = IntPtr.Zero;
IntPtr open = InternetOpen("Portal", 1, null, null, 0x10000000);
IntPtr connected = InternetConnect(open, uri, 21, userName, password, 1, 0x08000000, context);
if (!FtpCommand(connected, false, 0x00000001, "SITE CHMOD 775 " + fileName, context, out ftpCommand)) return false;
bool connectedclose = InternetCloseHandle(connected);
bool openclose = InternetCloseHandle(open);
return (connectedclose && openclose);
}
.
.
.
if (!ChangePermission("ftp://" + serverAddressTextBox.Text, ftpUserNameTextBox.Text, ftpPasswordTextBox.Text, masterDirectoryFileName))
richTextBox1.Text = "Permissions adjustment failed";
|
|
|
|
|
This project[^] may be of use. It has support for more FTP stuff than the .NET Framework.
I have used it successfully myself.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
There is only problem which is about the input string was not in the correct format. I use a textbox1 which is for me to type a number in the string format as I store the string in a variable knn. Then I try to convert it to Int32 and store it in another variable wup. However, after I tried to run the program, the error of input string popped up and I really run out of idea on what to do next.
public void find() {
int a = 0;
int h = 0;
Int32 t = 1;
int f = 130;
int d = 230;
string knn;
Int32 wup = 0;
knn = textBox1.Text;
wup = Convert.ToInt32(knn);
int [,] yes=new int[10,10];
for(a=0 ;a<=7 ; a++) {
for (h = 0; h <= 7; h++)
{
if (a == 0)
{
if( t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index = "+ Convert.ToString(t);
textBox3.Text = "x = " + Convert.ToString(a);
textBox4.Text = "y = " + Convert.ToString(h);
}
f = f + 20;
}
if (a == 0 && h == 7)
{
f = 130;
d = d + 20;
}
if (a == 1)
{
if (t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index = "+ Convert.ToString(t);
textBox3.Text = "x = " + Convert.ToString(a);
textBox4.Text = "y = " + Convert.ToString(h);
}
f = f + 20;
}
if (a == 1 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 2)
{
if (t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index"+ Convert.ToString(t);
textBox3.Text = "x" + Convert.ToString(a);
textBox4.Text = "y" + Convert.ToString(h);
textBox4.Text = textBox4.Text + Environment.NewLine + "y= " + (Convert.ToString(h));
}
f = f + 20;
}
if (a == 2 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 3)
{
if (t == wup)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text = "Index" + Convert.ToString(t);
textBox3.Text = "x" + Convert.ToString(a);
textBox4.Text = "y" + Convert.ToString(h);
}
f = f + 20;
}
if (a == 3 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 4)
{
if (t == wup){
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index = "+ Convert.ToString(t);
textBox3.Text = "x = " + Convert.ToString(a);
textBox4.Text = "y = " + Convert.ToString(h);
}
f = f + 20;
}
if (a == 4 && h == 7)
{
f = 130;
d = d + 30;
}
if (a == 5)
{
if (t == wup){
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle square = new System.Drawing.Rectangle(f, d, 5, 5);
graphics.DrawRectangle(System.Drawing.Pens.Red, square);
textBox2.Text ="Index"+ Convert.ToString(t);
textBox3.Text = "x" + Convert.ToString(a);
textBox4.Text = "y" + Convert.ToString(h);
}
f = f + 20;
}
yes[a, h] = t;
t++;
if (a == 5 && h == 7)
{
break;
}
}
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
}
}
modified 25-Jun-15 11:55am.
|
|
|
|
|
If you enter a none-integer value in your TextBox, Convert.ToInt32 is going to fail. In cases of parsing values, you really should use the appropriate TryParse instead, so you would expect this to be something like
int value;
if (!int.TryParse(myStringValue, out value))
{
return;
}
|
|
|
|
|
I am still unsure about what you commented. So I just need to insert this chunk into my code? In addition, int value represents which variable of mine? I am actually quite new to programming so please help me.
|
|
|
|
|
Remove the lines
knn = textBox1.Text;
wup = Convert.ToInt32(knn); and replace with
if (!int.TryParse(textBox1.Text, out wup))
{
MessageBox.Show("Please enter an integer value");
return;
}
Some other points ... instead of using
textBox2.Text = "Index = " + Convert.ToString(t); you can use the built-in ToString() method e.g.
textBox2.Text = "Index = " + t.ToString(); or possibly even better
textBox2.Text = String.Format("Index = {0}", t); There is more tidying up you could do but I'll leave it there
|
|
|
|
|
hi
Does anyone experienced in the text-to-speech in C# WinForm ?
Is it possible to get a clue or direction ?
thanks
|
|
|
|
|
Have you tried searching the articles[^] or even Google. They will give you a clue and an example you can work through.
The forums are for asking specific question or starting a discussion use the articles for research.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
goldsoft wrote: Is it possible to get a clue "MS Agent"
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am trying to make and Android app with ASP.NET WebService. In WebService, if I want to return values from a single table I know what to do :
public DataTable GetUserDetails(string userName)
{
....
return userDetailsTable;
}
But I don't know what to do if I want to return values from different tables (a more complex data). Should I use
List<DataTable> or something else? If I use
List<DataTable> , how should I handle it in Android side? Thanks.
|
|
|
|
|
Returning things like DataTable is generally a bad idea, especially if your client needs to be lean and use minimal data resources. When you return a DataTable you get a lot of stuff returned, when you are normally just interested in the data.
What people normally do is define a class object that represents the bits of data you want to return. So if you want to return a Customer table you'll create a Customer class with properties like ID, FirstName, Surname etc, then in your web method you create a List<customer> and for each row of your datatable you'll create a Custom object, populate the properties from the fields, add it to the List<customer> and then return the List. This will greatly reduce the amount of data sent to your app, and your app now just sees a simply collection with just the data it needs.
|
|
|
|
|
Thank you very much for your reply. Can you tell me how I should make Android could handle List< Customer >? A sample code would be great. Moreover is it a good idea to send List< Customer > and List< Order > at the same time?
Thanks a lot.
|
|
|
|
|
No idea TBH, this is a c# forum, I don't know anything about Android apps. Although you are return a List, .net will convert that to json so your Android app should see something like
[{ID:1, FirstName: "John", LastName: "Doe"}, {ID=2, FirstName: "Dave", LastName: "Smith"}]
whatever framework Android has for calling web services will know how to parse that.
|
|
|
|
|
How to store the result into a byte[] with this declaration:
private static T Get<T>(string resource, out string jsonResponse) where T : class
Thanks
|
|
|
|
|
Are you talking about the value in jsonResponse here, or the value from your return statement? If it's the jsonResponse, you can use
Encoding.ASCII.GetBytes(jsonResponse);
|
|
|
|
|
That's very helpful. Thanks very much.
|
|
|
|
|
I have developed win form application. I have MDI form and I have created many child forms. When I click ribbon control tab child forms rendering not properly. when it's showing some shaking and blurring appeared after its showing properly. It is take some time.
I have using TableLayout panel within form
|
|
|
|
|
Not enough information. We have no idea what you mean by "When I click ribbon control tab child forms rendering not properly "when it's showing some shaking and blurring appeared after its showing properly. It is take some time."
We also have no idea what you're code looks like and what its doing.
|
|
|
|
|
Hi,
Can any body help me for developing email solution for local network with mail server and own mail domain(mdccb.com) in C#
|
|
|
|
|
|
Hi,
This example retrieves a pdf document.
How can I save the data as a pdf file to disk?
Thanks
string jsonResponse ;
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(string uri);
webRequest.Method = "GET";
webRequest.Accept = "application/pdf";
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
{
jsonResponse = reader.ReadToEnd();
}
}
|
|
|
|
|
You will receive the PDF in "plain binary", not JSON, so you can simply copy the stream contents into a file (-stream):
string uri = "some pdf uri";
string filename = "some filepath";
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
webRequest.Method = "GET";
webRequest.Accept = "application/pdf";
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
using (Stream responseStream = webResponse.GetResponseStream())
{
using (FileStream fileStream = File.Create(filename))
{
responseStream.CopyTo(fileStream);
}
}
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|