-1

I have folder on server and server can be access using public IP with user name and password. I want to access folder and want to read/write files in folder programmatically in C#.

I go through Google but could find any answer. I have to use IP, username and password to access the folder.

halfer
  • 19,824
  • 17
  • 99
  • 186
Scor Pio
  • 49
  • 2
  • 13
  • 1
    Assuming you are talking about SMB file shares see here: http://stackoverflow.com/questions/659013/accessing-a-shared-file-unc-from-a-remote-non-trusted-domain-with-credentials If you are using some other protocol, you should mention what protocol you want to use. (FTP?) – dodald Sep 16 '14 at 17:26
  • The information i have is only that i have public ip of address,user name and password, Which protocol should i used and how i can do it. Please help me. – Scor Pio Sep 16 '14 at 17:45
  • You are unfortunately missing a critical piece of information, without the protocol you cannot proceed. If you are on a Windows based network you can likely assume that SMB is the protocol (See my previous comment). – dodald Sep 16 '14 at 18:04
  • i go through SMB protocol and i have to use it. But in your previous post the question you mention,require computer name, domian with user name and password. As below using (NetworkShareAccesser.Access(REMOTE_COMPUTER_NAME, DOMAIN, USER_NAME, PASSWORD)) { File.Copy(@"C:\Some\File\To\copy.txt", @"\\REMOTE-COMPUTER\My\Shared\Target\file.txt"); } ...... But i have the IP, User Name and Password. How i will use it? – Scor Pio Sep 16 '14 at 18:12
  • There is an overload that does not require a domainname (Access(string remoteComputerName, string userName, string password)) – dodald Sep 16 '14 at 18:35
  • I should add you should be able to use the ip address as the computer name. (e.g. Access("192.168.12.12", "TheUserName", "ThePassWord")) – dodald Sep 16 '14 at 20:18
  • Now i have the folder at this path "file://rscms.raaziq.com.pk/EDI/CP/". If you paste this URL you will find two folder i.e export and import. I want to get the files from import folder and want to create the date wise folder in export and want to create the DAT in date wise folder and want to write in. Please help me in this regard. Thanks – Scor Pio Sep 17 '14 at 19:23

1 Answers1

2

If you are using the FileZilla client to transfer your files from your computer to your server , you can right click the file or folder in the right panel in your FileZilla client and click File Permissions to change the permissions on read/write/execute etc.

XML file:

<?xml version="1.0" encoding="utf-8" ?>
<test1>
<version>3.2.0.0</version>
<url>http://www.google.com</url>
</test1>    

C# code for read:
string versionString; string downloadUrl;

Version newVersion = null;
string xmlUrl = "http://www.yourXmlLocation.com/test123.xml";
XmlTextReader reader = null;
try
{ 
    reader = new XmlTextReader(xmlUrl);
    reader.MoveToContent();
    string elementName = "";
    if((reader.NodeType == XmlNodeType.Element ) && (reader.Name == "test1"))
    {
        while (reader.Read())
        {
            if(reader.NodeType == XmlNodeType.Element)
            {
                elementName = reader.Name;
            }
            else
            {
                if((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
                {
                    switch(elementName)
                    {
                        case "version":                                        
                            versionString = reader.Value;
                            break;
                        case "url":
                            downloadUrl = reader.Value;
                            break;
                    }
                }
            }
        }
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex);
}
if (reader != null)
    reader.Close();

This is how you get values versionString = "3.2.0.0" , downloadURL = "http://www.google.com".

dimitris93
  • 4,155
  • 11
  • 50
  • 86
  • I am not using filezilla. I have to use SMB to read\write files in folder programmatically in C# – Scor Pio Sep 16 '14 at 18:15
  • what kind of files are you trying to read write ? is it just a .txt you want to read ? a .xml ? – dimitris93 Sep 16 '14 at 18:16
  • 1
    You are saying you want to read/write files. my question is , what files ? are you trying to read a .txt file from a server ? what are you trying to do? - oh you said .txt and xml i thought your answer was a question - i ll update my answer soon. – dimitris93 Sep 16 '14 at 18:18
  • I am using below code in c# to read file from folder which is on my computer String str = @"E:\\Folder"; string[] filePaths = Directory.GetFiles(str, "*.xml"); But now i want to read\write files from folder which is on another computer or server and on other network which has public IP with user name and password. Now how i can do this? – Scor Pio Sep 16 '14 at 18:26
  • was that what you were looking for ? - that is a simple read of a xml file that u have uploaded on a URL http://www.yourXmlLocation.com/test123.xml – dimitris93 Sep 16 '14 at 18:32
  • No dear....Where will i put IP , User name and password to access folder and read files? – Scor Pio Sep 16 '14 at 19:43
  • I don't think you can access a .xml file if you haven't uploaded that .xml file in a website with an actual URL. And i dont see the point of wanting to do something like that. How can you have IP/username/pass information of a server you own, and have 0 domain names linked with that server, thats strange. Why dont you just get a free .tk domain and link that with your server, and then uploaded to your site www.mysite.tk/myxml.xml ?... Also if you only want to read/write an xml file, just upload it to dropbox and use the url from there... but yea... – dimitris93 Sep 16 '14 at 20:02
  • Another problem with what you are trying to do, is that even if you had the code that could read/write a .xml file from your server using IP/username/pass information, that server would not accept the connection between you and the server. Its similar with making a C# application that connects to a database of a server using IP/username/password. To do that you have to manually add your own IP address to the 'whitelist' of that server (usually through a cPanel you get when you purchase a server) otherwise your connection will be rejected. – dimitris93 Sep 16 '14 at 20:24
  • Now i have the folder at this path "file://rscms.raaziq.com.pk/EDI/CP/". If you paste this URL you will find two folder i.e export and import. I want to get the files from import folder and want to create the date wise folder in export and want to create the DAT in date wise folder and want to write in. – Scor Pio Sep 17 '14 at 19:24
  • that URL doesnt open on my computer, and this chat is very spammy, be careful, your post might get blocked for spamming the comment section – dimitris93 Sep 17 '14 at 19:27