I have load xml from remote machine - c#

I have url like
http://steepgraph5-pc/sgs/Client/Innovator.xml
from that url I load Innovator.xml into XmlDocument and get node that contain path like
C:\\Program Files (x86)\\Aras\\Innovator\\InnovatorServerConfig.xml
now I have to load InnovatorServerConfig.xml into new XmlDocumnet but this path is local to server and i have to load it from client. I am using c#
C# code is like:
XmlDocument document = new XmlDocument();
document.Load("http://steepgraph5-pc/sgs/Client/Innovator.xml");
string path=document.SelectSingleNode("/ConfigFilePath/#value").Value;
XmlDocument ServerConfigdocument = new XmlDocument();
ServerConfigdocument.Load(path);

There is no way to convert an arbitrary file system path to a means to access that path from a remote computer.
You need to have some sort of network protocol to access it. You appear to have selected HTTP.
Given that you are using HTTP, you have to:
Be wanting to access a file that the server actually makes available
Know how the server maps its Document Root onto the file system
Then you can convert the file path to a URL.
This isn't a sensible thing to do on the client. It would make more sense for the server to rewrite the XML and replace the local path with an HTTP URI.

Innovator server config is just a file loaded by the Innovator server side when it starts up.
If you edit it it will have no effect until you restart the IIS webserver.
I'd recommend just remote desktop to the server, edit the file and restart the webserver.
If you wish to to this remotely, then you can make the Innovator root folder accessible via WEBDAV. This can be mounted or browsed by any remote machine as though it is a local disk.
Then after editing, use the remote management capability of IIS to restart the server.

Related

loading a file from http to a local filepath temporarily using c# webclient

I want to save a file from a http link to the local drive just temporarily in order to access it, this one is working so far and I'm getting the data but a need to write this data to a local file, for example to C:\Windows\temp\test.text, this file should be deleted afterwards.
WebClient client = new WebClient();
string url = "http://www.example.com/test.text";
var file = client.DownloadData(url);
could any one help me on this, thank you!
You cannot write a file on client machine due to security, Any program executing in the browser executes within the browser sandbox and has access to limited features like printer, cookies, etc.
You can write the data to file as a Response object to the client's browser. The Client has the choice of whether to save it or not to his machine.

Server.Mappath() fail on remote server

i use like this codes for prepare paths.
string path = Server.MapPath("~/"+ User.Identity.Name+ "/file.zip");
i take this error when i run this code on localhost
Index:582 Not allowed to load local resource: file:///C:/Users/trkmml/Documents/GitHub/OfisTakip/trkmml/file.zip
i think its not problem (its chrome security thing). anyway file path is correct.
On the other hand, when I upload the program to hosting, it adds "file:///C:/Inetpub/vhosts" to the front of the link. how can i cancel this part. how do I make it just
http://example.com/httpdocs/trkmml/file.zip".
here is error on remote host
Not allowed to load local resource: file:///C:/Inetpub/vhosts/example.com/httpdocs/trkmml/file.zip

How to find a file in server based on name in c#

I have an xml named Mapping.xml stored in my local system. i am accessing in code ,in my local system like XDocument xd = new XDocument(#"D:\MVCPopup\Mapping.xml"); .But i don't think this will work if i deploy it in iis server due to the folder structure change.Do we have a generic mechanism which will find the file Mapping.xml. Will Server.Mappath will work here?
Server.MapPath returns the phisical address from a virtual one. So if you configure a virtual folder on the iis that maps to the folder you save your XML in, then yes, Server.MapPath will help.

trying to upload a file to Ftp but getting the error: "file name not allowed"!

So I was trying to upload a 1kb text file to my ftp server but this error comes up:
The remote server returned an error: (553) File name not allowed.
so what's wrong with my code?
WebClient upload = new WebClient();
upload.Credentials = new NetworkCredential("******", "*********");
upload.UploadFile("ftp://xxx.com/public_html", "G:/adress.txt");
It's hard to tell, because it's a server error not a code error. However, as currently written, you're trying to upload the file called adress.txt to become a file named public_html. I suspect there's already a directory with that name, and the conflict is preventing the upload. Try
upload.UploadFile("ftp://xxx.com/public_html/adress.txt", "G:/adress.txt");
instead.
This might not apply to you, but if it is a Linux FTP server:
This may help for Linux FTP server.
So, Linux FTP servers unlike IIS don't have common FTP root directory.
Instead, when you log on to FTP server under some user's credentials,
this user's root directory is used. So FTP directory hierarchy starts
from /root/ for root user and from /home/username for others.
So, if you need to query a file not relative to user account home
directory, but relative to file system root, add an extra / after
server name. Resulting URL will look like:
ftp://servername.net//var/lalala
Instead of:
ftp://xxx.com/public_html
You would need a second slash after the server name in addition to the full file name:
ftp://xxx.com//public_html/adress.txt
I ran into this same issue and it fixed it for me.
Source:
Can't connect to FTP: (553) File name not allowed

Download File via Tamir.SharpSSH.Sftp.Get()

I'm trying to download a file using the Tamir SSH library. I'm able to connect to the remote FTP site, upload files to the site, but I'm getting exceptions when trying to download. I've given IIS_IUSRS full control of the local directory as well as ASPNET. I've tested an I'm able to create a text file in the same local directory I'm trying to download to. Any ideas?
string SFTP_HOST = ConfigurationManager.AppSettings["AccentivFtpHost"];
string SFTP_USERNAME = ConfigurationManager.AppSettings["AccentivFtpUsername"];
string SFTP_PASSWORD = ConfigurationManager.AppSettings["AccentivFtpPassword"];
Sftp client = new Sftp(SFTP_HOST, SFTP_USERNAME, SFTP_PASSWORD);
client.Connect(22);
client.Get("test.txt", "c:\\test.txt");
You probably lack a '/' character in the file directory. You may need to put it either in the Get function call before the "test.txt" like "/test.txt" or at the end of your AccentivFtpHost value in the app config file.

Categories