C# connect to remote server using Microsoft Terminal Services Active Client (RDP) - c#

I have a piece of code that should connect to the server. The code is as following:
var rdp = new MsRdpClient8NotSafeForScripting();
rdp.Server = "192.168.0.101"; //adress
rdp.Domain = "localdomain"; //domain
rdp.UserName = "test"; //login
rdp.AdvancedSettings8.ClearTextPassword = "123456";//password
try
{
rdp.Connect();
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.WriteLine(rdp.Connected);
if (rdp.Connected != 0)
{
rdp.Disconnect();
}
Console.ReadLine();
This is supposed to "connect" to my remote server via 3389 port so that I can be able to read a file from my desktop which is called: "min.txt"
So far I have tried specifying the login data of my server but I always just get output of "0" in the console's window, regardless of whether I specify correct or incorrect login data..
My questions here are:
Why is it connecting even with wrong login data (ip, user + password)
How can I, once I've been indeed successfully connected to the server, access the min.txt file on my remote server, which is located at desktop...
Can someone help me out?

Probably you can try specifying the password like below:
MSTSClib.IMsTscNonScriptable secured = (MSTSClib.IMsTscNonScriptable)rdp.GetOcx();
secured.ClearTextPassword = “123456”;
For reference: MSDN link is here
Once connected, you can access the file like a shared network file via UNC.
Example:
System.IO.FileStream stream = System.IO.File.OpenRead("\\servername\sharedname\path\somefile.txt");
Then need to ensure that permissions are in place to access the folder.

Related

SoftEther Authentication "Access denied"

I'm using SoftEther APIs to connect to a VPS and then try to build a VPN on that .
I can successfully connect to server using IP and Port, then at Authentication step I get "Access denied" and no more details.
The authentication step is using Password and HubName.
I've read the APIs codes deeply and I realized it using SHA0 algorithm to encrypt password and take a random arrays of bytes from server and use that as salt in encrypt method .
So I've changed the encryption method at SoftEther Application to AES128 , AES256 and some others but the result has not been changed at all.
I also tried to send password as an ASCII but none of them worked.
The exact API code without change:
using (var softEther = new SoftEther(ip, port))
{
// the connection step that would pass successfully :
var connectResult = softEther.Connect();
if (!connectResult.Valid())
{
Console.WriteLine(connectResult.Error);
return;
}
// the Authentication step that got problem :
var authResult = softEther.Authenticate(pw, hubName);
if (!authResult.Valid())
{
Console.WriteLine(authResult.Error);
return;
}
// the code stops and don't get here :
var user = softEther.HubApi.GetUser(hubName, userName);
Console.WriteLine(user.Valid() ? "Success" :
user.Error.ToString());
}
And this is the authResult I get
Well since you are working on server side of SoftEther i would recommend you to use VPNCMD for managing or retrieving info from SoftEther server.
VPNCMD Virtual Hub commands:
https://www.softether.org/4-docs/1-manual/6._Command_Line_Management_Utility_Manual/6.4_VPN_Server_%2F%2F_VPN_Bridge_Management_Command_Reference_(For_Virtual_Hub)
For example enter the following in cmd/terminal:
vpncmd /server {serverIP} /PASSWORD:{server password}
/adminhub:{server HUB Name} /CMD UserCreate {username}
/GROUP:{groupname} /REALNAME:{user fullname} /NOTE:{anything}
Requirements:
Download and install SoftEther server manager for your machine OS(ie from where you want to control remote server)
You can also execute VPN Client functions from VPNCMD:https://www.softether.org/4-docs/1-manual/6._Command_Line_Management_Utility_Manual/6.5_VPN_Client_Management_Command_Reference

SftpClient using Url instead of IP as host

I am using the following code to upload a file to an sFTP server. I have done a test upload using FileZilla and the file is uploaded successfully.
try
{
var client = new SftpClient(host, port, username, password);
client.Connect();
client.ChangeDirectory(workingDir);
var listDirectory = client.ListDirectory(workingDir);
foreach (var file in files)
{
var fileStream = new FileStream(file, FileMode.OpenOrCreate);
client.BufferSize = 4 * 1024; // bypass payload error large files
client.UploadFile(fileStream, Path.GetFileName(file));
Log.Info(string.Format("File [{0}] upload complete",file));
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
But in the code above, I cannot seem to get the upload done because I get the following error:
No such host is known
And that's maybe because I am using the Url value of my host instead of IP? (I have done a test with another FtP server using IP and that also seems to be working) I'm wondering if that's the case? If so, is there a way to let SftpClient (Ssh.Net) handle the Url?
The host parameter may be an IP address or a host name that can be resolved to an IP address. It may not be a URL, that is something completely different from a technical point of view.
The fact that some full application accepts something else than a host name says little: it splits that string into separat tokens and connects to the IP address it gets returned when resolving the host name. But that does not mean that you can open any network connection to a URL or some arbitrary string. It is only possible to open a connection to an IP address.
So if you successfully test some URL like sftp://ftp.example.com/ContactImport in some "program", this does not mean that you can internally use that string as host parameter in your code. You need to use the host name that is a part of such URL, so ftp.example.com in this case, since only that can be successfully resolved to an IP address.

SSRS Report Portal Management

I am working on an C# utility that would help clients publishing SSRS reports on their sites. Here my code:
public void createFolder()
{
ReportingService2010 rs = new ReportingService2010();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create a custom property for the folder.
Property newProp = new Property();
newProp.Name = "Department";
newProp.Value = "Finance";
Property[] props = new Property[1];
props[0] = newProp;
string folderName = "Budget";
try
{
rs.CreateFolder(folderName, "/", props);
Console.WriteLine("Folder created: {0}", folderName);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.InnerXml);
}
}
I am getting the following error:
ErrorCode xmlns="http://www.microsoft.com/sql/reportingservices">rsAccessDenied</ErrorCode><HttpStatus xmlns="http://www.microsoft.com/sql/reportingservices">400</HttpStatus><Message xmlns="http://www.microsoft.com/sql/reportingservices">The permissions granted to user 'NT AUTHORITY\NETWORK SERVICE' are insufficient for performing this operation.</Message><HelpLink xmlns="http://www.microsoft.com/sql/reportingservices">https://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=rsAccessDenied&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=13.0.1601.5</HelpLink><ProductName xmlns="http://www.microsoft.com/sql/reportingservices">Microsoft SQL Server Reporting Services</ProductName><ProductVersion xmlns="http://www.microsoft.com/sql/reportingservices">13.0.1601.5</ProductVersion><ProductLocaleId xmlns="http://www.microsoft.com/sql/reportingservices">127</ProductLocaleId><OperatingSystem xmlns="http://www.microsoft.com/sql/reportingservices">OsIndependent</OperatingSystem><CountryLocaleId xmlns="http://www.microsoft.com/sql/reportingservices">1033</CountryLocaleId><MoreInformation xmlns="http://www.microsoft.com/sql/reportingservices"><Source>ReportingServicesLibrary</Source><Message msrs:ErrorCode="rsAccessDenied" msrs:HelpLink="https://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=rsAccessDenied&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=13.0.1601.5" xmlns:msrs="http://www.microsoft.com/sql/reportingservices">The permissions granted to user 'NT AUTHORITY\NETWORK SERVICE' are insufficient for performing this operation.</Message></MoreInformation><Warnings xmlns="http://www.microsoft.com/sql/reportingservices" />
Any idea?
Please note that a point of this exercise is not just get it work but knowing that it is going to run on a client side ideally without any tweaking on their part.
Thanks for help.
Your question is a little unclear. It sounds like you're not sure why you're getting a permissions error. The answer is that you need to create a new role. I assume (after your comment) that your question is how you can do that using C#.
You can use the CreateRole() method, which will only work with SSRS Native Mode. If SSRS is installed in SharePoint Integrated mode, there is no supported method other than using the UI.
This method throws an OperationNotSupportedSharePointMode exception
when invoked in SharePoint mode

.NET WebClient works on my localhost but not on Azure

I'm trying to FTP a file from Azure up to some FTP destination.
When I do it locally, it's working great. Ok ...
I publish this webjob up to azure and it's works great until it tries to do the FTP bit.
The following error is shown:
[12/21/2015 03:18:03 > 944464: INFO] 2015-12-21 03:18:03.6127| ERROR| Unable to connect to the remote server. Stack Trace: at System.Net.WebClient.UploadFile(Uri address, String method, String fileName)
[12/21/2015 03:18:03 > 944464: INFO] at System.Net.WebClient.UploadFile(String address, String method, String fileName)
And this is my simple code...
public void UploadFile(FileInfo fileInfo)
{
try
{
using (var client = new WebClient())
{
var destination = new Uri($"ftp://{_server}/{fileInfo.Name}");
client.Credentials = new NetworkCredential(_username, _password);
client.UploadFile(destination, "STOR", fileInfo.FullName);
}
}
catch (Exception exception)
{
// snipped.
throw;
}
}
So it's pretty damn simple.
Could this be some weird PASSIVE/ACTIVE issue? Like, how our office internet is simple while azure's setup is complex and ... as such ... it just cannot create the FTP connection?
Now - this is where things also get frustrating. Originally I was using a 3rd party FTP library and that DID work .. but some files were only getting partially uploaded .. which is why i'm trying to use WebClient instead. So I know that my azure webjob "website" thingy can FTP up. (no blocked ports, etc).
Any clues to what I can do, here?
Following Kristensen's simple example, I could do it. But I'm not sure about the format of your FTP url destination.
Did you try:
var destination = new Uri(string.Format("ftp://{0}/{1}", _server,fileInfo.Name));
Assuming _server is defined somewhere, I don't see it in your code and that your credentials have permissions to write on that location.

Cannot retrieve perforce clients

I am trying to develop a C# based build tool using p4api.net apis. I am new to perforce p4api.net. I followed the instructions given in p4api.net library downloaded from their site, but was never successful in running a basic command on perforce. I am attaching piece of code which is supposed to fetch clients from Perforce. Please correct it, if am wrong. The code throws a run time error (unhandled expection) while executing GetClients().
static void Main(string[] args)
{
string uri = "perforce:1666";
string user = "User1";
Server server = new Server(new ServerAddress(uri));
Repository rep = new Repository(server);
Connection con = rep.Connection;
con.UserName = user;
con.Client = new Client();
// connect to the server
con.Connect(null);
// run the command against the current repository
IList<Client> changes = rep.GetClients(null);
}
Any useful guide to perforce C# documents/examples would be appreciated.
Thanks,
Madhu
tickets are granted to the user by p4 login. If you login with P4V or another client the ticket should still be valid until expiration unless you explicitly p4 logout. You can create this credential in P4API.NET after you connect and before you run a command:
// connect to the server
con.Connect(null);
string password = "pw";
Credential cred = con.Login(password, null, null);
con.Credential = cred;
Are you sure that the exception is coming from GetClients? I ran your code successfully, but when I changed uri to a non-existent server:port I get the unhandled exception at con.Connect(null).
Confirm that you do have access to a perforce:1666 server with User1 and that User1 does not require a password on that server.

Categories